Browse Source

Fixed bug in IN operator evaluation.

pull/183/merge
Kalle Stenflo 9 years ago
parent
commit
fd2ac6c0be
  1. 12
      json-path/src/main/java/com/jayway/jsonpath/internal/filter/EvaluatorFactory.java
  2. 10
      json-path/src/test/java/com/jayway/jsonpath/FilterTest.java

12
json-path/src/main/java/com/jayway/jsonpath/internal/filter/EvaluatorFactory.java

@ -145,7 +145,17 @@ public class EvaluatorFactory {
private static class InEvaluator implements Evaluator { private static class InEvaluator implements Evaluator {
@Override @Override
public boolean evaluate(ValueNode left, ValueNode right, Predicate.PredicateContext ctx) { public boolean evaluate(ValueNode left, ValueNode right, Predicate.PredicateContext ctx) {
ValueNode.ValueListNode valueListNode = right.asValueListNode(); ValueNode.ValueListNode valueListNode;
if(right.isJsonNode()){
ValueNode vn = right.asJsonNode().asValueListNode(ctx);
if(vn.isUndefinedNode()){
return false;
} else {
valueListNode = vn.asValueListNode();
}
} else {
valueListNode = right.asValueListNode();
}
return valueListNode.contains(left); return valueListNode.contains(left);
} }
} }

10
json-path/src/test/java/com/jayway/jsonpath/FilterTest.java

@ -479,4 +479,14 @@ public class FilterTest extends BaseTest {
criteria = Criteria.parse("@.foo"); criteria = Criteria.parse("@.foo");
assertThat(criteria.toString()).isEqualTo("@['foo']"); assertThat(criteria.toString()).isEqualTo("@['foo']");
} }
@Test
public void inline_in_criteria_evalueates() {
Object read = JsonPath.read(JSON_DOCUMENT, "$.store.book[?(@.category in ['reference', 'fiction'])]");
System.out.println(read);
}
} }

Loading…
Cancel
Save