Browse Source

Incorrect error message for JsonPath.read(Object) #89

pull/148/head
Kalle Stenflo 9 years ago
parent
commit
8647a607da
  1. 3
      json-path/src/main/java/com/jayway/jsonpath/internal/token/PropertyPathToken.java
  2. 12
      json-path/src/test/java/com/jayway/jsonpath/old/IssuesTest.java

3
json-path/src/main/java/com/jayway/jsonpath/internal/token/PropertyPathToken.java

@ -38,7 +38,8 @@ class PropertyPathToken extends PathToken {
@Override
public void evaluate(String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx) {
if (!ctx.jsonProvider().isMap(model)) {
throw new PathNotFoundException("Property " + getPathFragment() + " not found in path " + currentPath);
//throw new PathNotFoundException("Property " + getPathFragment() + " not found in path " + currentPath);
throw new PathNotFoundException("Expected to find an object with property " + getPathFragment() + " but found '" + model.getClass().getName() + "'. This is not a json object according to the JsonProvider: '" + ctx.configuration().jsonProvider().getClass().getName() + "'.");
}
handleObjectProperty(currentPath, model, ctx, properties);

12
json-path/src/test/java/com/jayway/jsonpath/old/IssuesTest.java

@ -1,5 +1,6 @@
package com.jayway.jsonpath.old;
import com.google.gson.JsonObject;
import com.jayway.jsonpath.BaseTest;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.DocumentContext;
@ -875,4 +876,15 @@ public class IssuesTest extends BaseTest {
assertThat(numbers).containsExactly(8.95D, 12.99D, 8.99D, 22.99D);
}
@Test(expected = PathNotFoundException.class)
public void github_89() {
com.google.gson.JsonObject json = new JsonObject();
json.addProperty("foo", "bar");
JsonPath path = JsonPath.compile("$.foo");
String object = path.read(json);
}
}

Loading…
Cancel
Save