Browse Source

Merge 2acf2e0437 into 45333e0a31

pull/679/merge
zengmmm00 1 year ago committed by GitHub
parent
commit
fc4bce9f8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      json-path/src/main/java/com/jayway/jsonpath/JsonPath.java
  2. 41
      json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue628.java

1
json-path/src/main/java/com/jayway/jsonpath/JsonPath.java

@ -533,6 +533,7 @@ public class JsonPath {
*/
@SuppressWarnings({"unchecked"})
public static <T> T read(Object json, String jsonPath, Predicate... filters) {
if (String.valueOf(json).equals("{}") ) return null;
return parse(json).read(jsonPath, filters);
}

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

@ -0,0 +1,41 @@
package com.jayway.jsonpath.internal.function;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.Predicate;
import org.junit.Test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertNull;
public class Issue628 {
@Test
public void testEmptyConfiguration() {
String document = "{}";
Configuration config = Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build();
String nonExistentPath = "$.doesNotExist";
assertNull(JsonPath.read(config.jsonProvider().parse(document), nonExistentPath));
}
@Test
public void testReadingEmptyMapWithFilter(){
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