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)) { } else if (CriteriaType.EXISTS.equals(key)) {
boolean exp = (Boolean) expectedVal; final boolean exp = (Boolean) expectedVal;
boolean act = true; return objectOrAnyCollectionItemMatches(map, new Predicate<Object>() {
try{
this.key.read(map); @Override
}catch (InvalidPathException e){ public boolean accept(final Object value) {
act = false; 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)) { } else if (CriteriaType.TYPE.equals(key)) {

Loading…
Cancel
Save