diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/compiler/ScanPathToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/compiler/ScanPathToken.java index a8e1323d..8e266a38 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/compiler/ScanPathToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/compiler/ScanPathToken.java @@ -197,8 +197,11 @@ public class ScanPathToken extends PathToken { @Override public boolean matches(Object model) { - Collection keys = ctx.jsonProvider().getPropertyKeys(model); - return keys.containsAll(propertyPathToken.getProperties()); + if(ctx.jsonProvider().isMap(model)){ + Collection keys = ctx.jsonProvider().getPropertyKeys(model); + return keys.containsAll(propertyPathToken.getProperties()); + } + return false; } } } diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/AbstractJsonProvider.java b/json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/AbstractJsonProvider.java index d43b98d4..e790b74a 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/AbstractJsonProvider.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/AbstractJsonProvider.java @@ -96,20 +96,15 @@ public abstract class AbstractJsonProvider implements JsonProvider { } /** - * Returns the keys from the given object or the indexes from an array + * Returns the keys from the given object * - * @param obj an array or an object - * @return the keys for an object or the indexes for an array + * @param obj an object + * @return the keys for an object */ @SuppressWarnings("unchecked") public Collection getPropertyKeys(Object obj) { if (isArray(obj)) { - List l = (List) obj; - List keys = new ArrayList(l.size()); - for (int i = 0; i < l.size(); i++) { - keys.add(String.valueOf(i)); - } - return keys; + throw new UnsupportedOperationException(); } else { return ((Map) obj).keySet(); } diff --git a/json-path/src/main/java/com/jayway/jsonpath/spi/json/JsonProvider.java b/json-path/src/main/java/com/jayway/jsonpath/spi/json/JsonProvider.java index 67ca5ed6..b1260f88 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/spi/json/JsonProvider.java +++ b/json-path/src/main/java/com/jayway/jsonpath/spi/json/JsonProvider.java @@ -62,10 +62,10 @@ public interface JsonProvider { /** - * Returns the keys from the given object or the indexes from an array + * Returns the keys from the given object * - * @param obj an array or an object - * @return the keys for an object or the indexes for an array + * @param obj an object + * @return the keys for an object */ Collection getPropertyKeys(Object obj);