@Test // https://github.com/json-path/JsonPath/issues/351 public 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();
@Test public void testJsonPathQuotesGson() throws Exception { final Configuration gson = Configuration.builder().jsonProvider(new GsonJsonProvider()).mappingProvider(new GsonMappingProvider()).build(); final DocumentContext ctx = JsonPath.using(gson).parse(JSON); final JsonArray doubleQuoteEqualsResult = ctx.read(DOUBLE_QUOTES_EQUALS_FILTER); assertEquals("bar", doubleQuoteEqualsResult.get(0).getAsString()); final JsonArray singleQuoteEqualsResult = ctx.read(SINGLE_QUOTES_EQUALS_FILTER); assertEquals(doubleQuoteEqualsResult, singleQuoteEqualsResult); final JsonArray doubleQuoteInResult = ctx.read(DOUBLE_QUOTES_IN_FILTER); assertEquals(doubleQuoteInResult, doubleQuoteEqualsResult); final JsonArray singleQuoteInResult = ctx.read(SINGLE_QUOTES_IN_FILTER); assertEquals(doubleQuoteInResult, singleQuoteInResult);
@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");
private void setJsonPathConfiguration() {
Configuration.setDefaults(new Configuration.Defaults() {
private final JsonProvider jsonProvider = new GsonJsonProvider();
private final MappingProvider mappingProvider = new GsonMappingProvider();
public JsonProvider jsonProvider() {
return jsonProvider;
public MappingProvider mappingProvider() {
return mappingProvider;
public Set<Option> options() {
return EnumSet.noneOf(Option.class);
private void setJsonPathConfiguration() {
Configuration.setDefaults(new Configuration.Defaults() {
private final JsonProvider jsonProvider = new GsonJsonProvider();
private final MappingProvider mappingProvider = new GsonMappingProvider();
public JsonProvider jsonProvider() {
return jsonProvider;
public MappingProvider mappingProvider() {
return mappingProvider;
public Set<Option> options() {
return EnumSet.noneOf(Option.class);
protected Configuration createJsonPathConfiguration() {
return new Configuration.ConfigurationBuilder()
.jsonProvider(new GsonJsonProvider())
.mappingProvider(new GsonMappingProvider())
.build();
private final MappingProvider mappingProvider = new GsonMappingProvider(gsonFuture);