Browse Source

interpret criteria key as JSONPath to allow filting on nested properties

pull/16/head
Jochen Berger 12 years ago
parent
commit
a545702151
  1. 8
      json-path/src/main/java/com/jayway/jsonpath/Criteria.java
  2. 4
      json-path/src/main/java/com/jayway/jsonpath/Filter.java

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

@ -48,7 +48,7 @@ public class Criteria {
*/ */
private static final Object NOT_SET = new Object(); private static final Object NOT_SET = new Object();
private final String key; private final JsonPath key;
private final List<Criteria> criteriaChain; private final List<Criteria> criteriaChain;
@ -61,17 +61,17 @@ public class Criteria {
notEmpty(key, "key can not be null or empty"); notEmpty(key, "key can not be null or empty");
this.criteriaChain = new ArrayList<Criteria>(); this.criteriaChain = new ArrayList<Criteria>();
this.criteriaChain.add(this); this.criteriaChain.add(this);
this.key = key; this.key = JsonPath.compile(key);
} }
private Criteria(List<Criteria> criteriaChain, String key) { private Criteria(List<Criteria> criteriaChain, String key) {
notEmpty(key, "key can not be null or empty"); notEmpty(key, "key can not be null or empty");
this.criteriaChain = criteriaChain; this.criteriaChain = criteriaChain;
this.criteriaChain.add(this); this.criteriaChain.add(this);
this.key = key; this.key = JsonPath.compile(key);
} }
public String getKey() { public JsonPath getKey() {
return this.key; return this.key;
} }

4
json-path/src/main/java/com/jayway/jsonpath/Filter.java

@ -101,8 +101,8 @@ public abstract class Filter<T> {
} }
public MapFilter addCriteria(Criteria criteria) { public MapFilter addCriteria(Criteria criteria) {
Criteria existing = this.criteria.get(criteria.getKey()); Criteria existing = this.criteria.get(criteria.getKey().getPath());
String key = criteria.getKey(); String key = criteria.getKey().getPath();
if (existing == null) { if (existing == null) {
this.criteria.put(key, criteria); this.criteria.put(key, criteria);
} else { } else {

Loading…
Cancel
Save