Search in sources :

Example 1 with GsonJsonProvider

use of com.jayway.jsonpath.spi.json.GsonJsonProvider 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");
}
Also used : GsonMappingProvider(com.jayway.jsonpath.spi.mapper.GsonMappingProvider) Configuration(com.jayway.jsonpath.Configuration) GsonJsonProvider(com.jayway.jsonpath.spi.json.GsonJsonProvider) DocumentContext(com.jayway.jsonpath.DocumentContext) BaseTest(com.jayway.jsonpath.BaseTest) Test(org.junit.Test)

Aggregations

BaseTest (com.jayway.jsonpath.BaseTest)1 Configuration (com.jayway.jsonpath.Configuration)1 DocumentContext (com.jayway.jsonpath.DocumentContext)1 GsonJsonProvider (com.jayway.jsonpath.spi.json.GsonJsonProvider)1 GsonMappingProvider (com.jayway.jsonpath.spi.mapper.GsonMappingProvider)1 Test (org.junit.Test)1