Browse Source

make EXISTS test work with collections

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

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

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

Loading…
Cancel
Save