Browse Source

make EXISTS test work with collections

pull/16/head
Jochen Berger 12 years ago
parent
commit
dbc3e7de3e
  1. 20
      json-path/src/main/java/com/jayway/jsonpath/Criteria.java

20
json-path/src/main/java/com/jayway/jsonpath/Criteria.java

@ -221,16 +221,26 @@ public class Criteria {
} else if (CriteriaType.EXISTS.equals(key)) {
boolean exp = (Boolean) expectedVal;
final boolean exp = (Boolean) expectedVal;
return objectOrAnyCollectionItemMatches(map, new Predicate<Object>() {
@Override
public boolean accept(final Object value) {
boolean act = true;
try{
this.key.read(map);
}catch (InvalidPathException e){
try {
Object val = getKey().read(value);
if(val instanceof Collection){
act = !((Collection) val).isEmpty();
}
} catch (InvalidPathException e) {
act = false;
}
return act == exp;
}
});
} else if (CriteriaType.TYPE.equals(key)) {
Class<?> exp = (Class<?>) expectedVal;

Loading…
Cancel
Save