Browse Source

update issue 628

pull/679/head
zengmmm00 4 years ago
parent
commit
0d8925922e
  1. 23
      json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue628.java

23
json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue628.java

@ -3,18 +3,39 @@ package com.jayway.jsonpath.internal.function;
import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Option; import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.Predicate;
import org.junit.Test; import org.junit.Test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
public class Issue628 { public class Issue628 {
@Test @Test
public void nonexistant_property_returns_null_when_configured() { public void empty_property_returns_null_when_configured() {
String document = "{}"; String document = "{}";
Configuration config = Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build(); Configuration config = Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build();
String nonExistentPath = "$.doesNotExist"; String nonExistentPath = "$.doesNotExist";
assertNull(JsonPath.read(config.jsonProvider().parse(document), nonExistentPath)); assertNull(JsonPath.read(config.jsonProvider().parse(document), nonExistentPath));
} }
@Test
public void empty_array_can_be_filtered(){
Map<String, Object> doc = new HashMap<String, Object>();
Predicate customFilter = new Predicate() {
@Override
public boolean apply(PredicateContext ctx) {
return 1 == (Integer)ctx.item();
}
};
List<Integer> res = JsonPath.read(doc, "$.items[?]", customFilter);
assertNull(res);
}
} }
Loading…
Cancel
Save