Browse Source

fix and test for 'not exists' serialization (fixes #178)

pull/196/head
Jochen Berger 9 years ago
parent
commit
8b26fae7b4
  1. 2
      json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java
  2. 9
      json-path/src/test/java/com/jayway/jsonpath/FilterCompilerTest.java

2
json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java

@ -801,7 +801,7 @@ public abstract class ValueNode {
@Override @Override
public String toString() { public String toString() {
return path.toString(); return existsCheck && ! shouldExist ? Utils.concat("!" , path.toString()) : path.toString();
} }
public ValueNode evaluate(Predicate.PredicateContext ctx) { public ValueNode evaluate(Predicate.PredicateContext ctx) {

9
json-path/src/test/java/com/jayway/jsonpath/FilterCompilerTest.java

@ -84,6 +84,15 @@ public class FilterCompilerTest {
assertInvalidPathException("[?(!'foo')]"); assertInvalidPathException("[?(!'foo')]");
} }
@Test
// issue #178
public void compile_and_serialize_not_exists_filter(){
Filter compiled = compile("[?(!@.foo)]");
String serialized = compiled.toString();
assertThat(serialized).isEqualTo("[?(!@['foo'])]");
}
private void assertInvalidPathException(String filter){ private void assertInvalidPathException(String filter){
try { try {

Loading…
Cancel
Save