Browse Source

don't use `JsonProvider.getPropertyKeys(Object)` to query a list/array's indexes

pull/53/head
Jochen Berger 10 years ago
parent
commit
a4bf433d68
  1. 3
      json-path/src/main/java/com/jayway/jsonpath/internal/compiler/ScanPathToken.java
  2. 13
      json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/AbstractJsonProvider.java
  3. 6
      json-path/src/main/java/com/jayway/jsonpath/spi/json/JsonProvider.java

3
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) {
if(ctx.jsonProvider().isMap(model)){
Collection<String> keys = ctx.jsonProvider().getPropertyKeys(model);
return keys.containsAll(propertyPathToken.getProperties());
}
return false;
}
}
}

13
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<String> getPropertyKeys(Object obj) {
if (isArray(obj)) {
List l = (List) obj;
List<String> keys = new ArrayList<String>(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();
}

6
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<String> getPropertyKeys(Object obj);

Loading…
Cancel
Save