Skip to content

Commit c6c092a

Browse files
committed
Merge pull request #196 from jochenberger/fix-not-exists-serialization
PR for #178
2 parents d958ab7 + 8b26fae commit c6c092a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ public PathNode asExistsCheck(boolean shouldExist) {
801801

802802
@Override
803803
public String toString() {
804-
return path.toString();
804+
return existsCheck && ! shouldExist ? Utils.concat("!" , path.toString()) : path.toString();
805805
}
806806

807807
public ValueNode evaluate(Predicate.PredicateContext ctx) {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ public void invalid_filters_does_not_compile() {
8484
assertInvalidPathException("[?(!'foo')]");
8585
}
8686

87+
@Test
88+
// issue #178
89+
public void compile_and_serialize_not_exists_filter(){
90+
Filter compiled = compile("[?([email protected])]");
91+
String serialized = compiled.toString();
92+
assertThat(serialized).isEqualTo("[?(!@['foo'])]");
93+
}
94+
95+
8796

8897
private void assertInvalidPathException(String filter){
8998
try {

0 commit comments

Comments
 (0)