Browse Source

Fixed issue 17. Use JsonProvider to check List or Map.

pull/13/merge
Kalle Stenflo 12 years ago
parent
commit
42d2e2e908
  1. 11
      json-path/src/main/java/com/jayway/jsonpath/JsonPath.java

11
json-path/src/main/java/com/jayway/jsonpath/JsonPath.java

@ -166,9 +166,10 @@ public class JsonPath {
/**
* Applies this JsonPath to the provided json document.
* Note that the document must either a {@link List} or a {@link Map}
* Note that the document must be identified as either a List or Map by
* the {@link JsonProvider}
*
* @param jsonObject a container Object ({@link List} or {@link Map})
* @param jsonObject a container Object
* @param <T> expected return type
* @return list of objects matched by the given path
*/
@ -176,11 +177,13 @@ public class JsonPath {
public <T> T read(Object jsonObject) {
notNull(jsonObject, "json can not be null");
if (!(jsonObject instanceof Map) && !(jsonObject instanceof List)) {
JsonProvider jsonProvider = JsonProviderFactory.createProvider();
if (!jsonProvider.isMap(jsonObject) && !jsonProvider.isList(jsonObject)) {
throw new IllegalArgumentException("Invalid container object");
}
LinkedList<Filter> contextFilters = new LinkedList<Filter>(filters);
JsonProvider jsonProvider = JsonProviderFactory.createProvider();
Object result = jsonObject;

Loading…
Cancel
Save