use of com.jayway.jsonpath.spi.mapper.GsonMappingProvider in project JsonPath by json-path.
the class GsonJsonProviderTest method no_error_when_mapping_null.
@Test
public // https://github.com/json-path/JsonPath/issues/351
void no_error_when_mapping_null() throws IOException {
Configuration configuration = Configuration.builder().mappingProvider(new GsonMappingProvider()).jsonProvider(new GsonJsonProvider()).options(Option.DEFAULT_PATH_LEAF_TO_NULL, Option.SUPPRESS_EXCEPTIONS).build();
String json = "{\"M\":[]}";
String result = JsonPath.using(configuration).parse(json).read("$.M[0].A[0]", String.class);
assertThat(result).isNull();
}
use of com.jayway.jsonpath.spi.mapper.GsonMappingProvider in project JsonPath by jayway.
the class IssuesTest method issue_97.
@Test
public void issue_97() throws Exception {
String json = "{ \"books\": [ " + "{ \"category\": \"fiction\" }, " + "{ \"category\": \"reference\" }, " + "{ \"category\": \"fiction\" }, " + "{ \"category\": \"fiction\" }, " + "{ \"category\": \"reference\" }, " + "{ \"category\": \"fiction\" }, " + "{ \"category\": \"reference\" }, " + "{ \"category\": \"reference\" }, " + "{ \"category\": \"reference\" }, " + "{ \"category\": \"reference\" }, " + "{ \"category\": \"reference\" } ] }";
Configuration conf = Configuration.builder().jsonProvider(new GsonJsonProvider()).mappingProvider(new GsonMappingProvider()).build();
DocumentContext context = JsonPath.using(conf).parse(json);
context.delete("$.books[?(@.category == 'reference')]");
List<String> categories = context.read("$..category", List.class);
assertThat(categories).containsOnly("fiction");
}
Aggregations