Search in sources :

Example 1 with JacksonJsonNodeJsonProvider

use of com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider in project JsonPath by json-path.

the class ProviderInTest method testJsonPathQuotesJacksonJsonNode.

@Test
public void testJsonPathQuotesJacksonJsonNode() throws Exception {
    final Configuration jacksonJsonNode = Configuration.builder().jsonProvider(new JacksonJsonNodeJsonProvider()).mappingProvider(new JacksonMappingProvider()).build();
    final DocumentContext ctx = JsonPath.using(jacksonJsonNode).parse(JSON);
    final ArrayNode doubleQuoteEqualsResult = ctx.read(DOUBLE_QUOTES_EQUALS_FILTER);
    assertEquals("bar", doubleQuoteEqualsResult.get(0).asText());
    final ArrayNode singleQuoteEqualsResult = ctx.read(SINGLE_QUOTES_EQUALS_FILTER);
    assertEquals(doubleQuoteEqualsResult, singleQuoteEqualsResult);
    final ArrayNode doubleQuoteInResult = ctx.read(DOUBLE_QUOTES_IN_FILTER);
    assertEquals(doubleQuoteInResult, doubleQuoteEqualsResult);
    final ArrayNode singleQuoteInResult = ctx.read(SINGLE_QUOTES_IN_FILTER);
    assertEquals(doubleQuoteInResult, singleQuoteInResult);
}
Also used : JacksonJsonNodeJsonProvider(com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider) JacksonMappingProvider(com.jayway.jsonpath.spi.mapper.JacksonMappingProvider) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Test(org.junit.Test)

Example 2 with JacksonJsonNodeJsonProvider

use of com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider in project JsonPath by jayway.

the class IssuesTest method issue_378.

@Test
public void issue_378() {
    String json = "{\n" + "    \"nodes\": {\n" + "        \"unnamed1\": {\n" + "            \"ntpServers\": [\n" + "                \"1.2.3.4\"\n" + "            ]\n" + "        }\n" + "    }\n" + "}";
    Configuration configuration = Configuration.builder().jsonProvider(new JacksonJsonNodeJsonProvider()).mappingProvider(new JacksonMappingProvider()).build();
    DocumentContext ctx = JsonPath.using(configuration).parse(json);
    String path = "$.nodes[*][?(!([\"1.2.3.4\"] subsetof @.ntpServers))].ntpServers";
    JsonPath jsonPath = JsonPath.compile(path);
    ctx.read(jsonPath);
}
Also used : JacksonJsonNodeJsonProvider(com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider) JacksonMappingProvider(com.jayway.jsonpath.spi.mapper.JacksonMappingProvider) Configuration(com.jayway.jsonpath.Configuration) DocumentContext(com.jayway.jsonpath.DocumentContext) JsonPath(com.jayway.jsonpath.JsonPath) BaseTest(com.jayway.jsonpath.BaseTest) Test(org.junit.Test)

Example 3 with JacksonJsonNodeJsonProvider

use of com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider in project JsonPath by json-path.

the class IssuesTest method issue_378.

@Test
public void issue_378() {
    String json = "{\n" + "    \"nodes\": {\n" + "        \"unnamed1\": {\n" + "            \"ntpServers\": [\n" + "                \"1.2.3.4\"\n" + "            ]\n" + "        }\n" + "    }\n" + "}";
    Configuration configuration = Configuration.builder().jsonProvider(new JacksonJsonNodeJsonProvider()).mappingProvider(new JacksonMappingProvider()).build();
    DocumentContext ctx = JsonPath.using(configuration).parse(json);
    String path = "$.nodes[*][?(!([\"1.2.3.4\"] subsetof @.ntpServers))].ntpServers";
    JsonPath jsonPath = JsonPath.compile(path);
    ctx.read(jsonPath);
}
Also used : JacksonJsonNodeJsonProvider(com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider) JacksonMappingProvider(com.jayway.jsonpath.spi.mapper.JacksonMappingProvider) Configuration(com.jayway.jsonpath.Configuration) DocumentContext(com.jayway.jsonpath.DocumentContext) JsonPath(com.jayway.jsonpath.JsonPath) BaseTest(com.jayway.jsonpath.BaseTest) Test(org.junit.Test)

Example 4 with JacksonJsonNodeJsonProvider

use of com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider in project JsonPath by jayway.

the class ProviderInTest method testJsonPathQuotesJacksonJsonNode.

@Test
public void testJsonPathQuotesJacksonJsonNode() throws Exception {
    final Configuration jacksonJsonNode = Configuration.builder().jsonProvider(new JacksonJsonNodeJsonProvider()).mappingProvider(new JacksonMappingProvider()).build();
    final DocumentContext ctx = JsonPath.using(jacksonJsonNode).parse(JSON);
    final ArrayNode doubleQuoteEqualsResult = ctx.read(DOUBLE_QUOTES_EQUALS_FILTER);
    assertEquals("bar", doubleQuoteEqualsResult.get(0).asText());
    final ArrayNode singleQuoteEqualsResult = ctx.read(SINGLE_QUOTES_EQUALS_FILTER);
    assertEquals(doubleQuoteEqualsResult, singleQuoteEqualsResult);
    final ArrayNode doubleQuoteInResult = ctx.read(DOUBLE_QUOTES_IN_FILTER);
    assertEquals(doubleQuoteInResult, doubleQuoteEqualsResult);
    final ArrayNode singleQuoteInResult = ctx.read(SINGLE_QUOTES_IN_FILTER);
    assertEquals(doubleQuoteInResult, singleQuoteInResult);
}
Also used : JacksonJsonNodeJsonProvider(com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider) JacksonMappingProvider(com.jayway.jsonpath.spi.mapper.JacksonMappingProvider) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Test(org.junit.Test)

Example 5 with JacksonJsonNodeJsonProvider

use of com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider in project JsonPath by jayway.

the class JacksonJsonNodeJsonProviderTest method mapPropertyWithPOJO.

@Test
public void mapPropertyWithPOJO() {
    String someJson = "" + "{\n" + "  \"a\": \"a\",\n" + "  \"b\": \"b\"\n" + "}";
    ObjectMapper om = new ObjectMapper();
    om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    Configuration c = Configuration.builder().mappingProvider(new JacksonMappingProvider()).jsonProvider(new JacksonJsonNodeJsonProvider(om)).build();
    DocumentContext context = JsonPath.using(c).parse(someJson);
    String someJsonStr = context.jsonString();
    DocumentContext altered = context.map("$['a', 'b', 'c']", new MapFunction() {

        @Override
        public Object map(Object currentValue, Configuration configuration) {
            return currentValue;
        }
    });
    assertThat(altered.jsonString()).isEqualTo(someJsonStr);
}
Also used : JacksonJsonNodeJsonProvider(com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider) JacksonMappingProvider(com.jayway.jsonpath.spi.mapper.JacksonMappingProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

JacksonJsonNodeJsonProvider (com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider)5 JacksonMappingProvider (com.jayway.jsonpath.spi.mapper.JacksonMappingProvider)5 Test (org.junit.Test)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 BaseTest (com.jayway.jsonpath.BaseTest)2 Configuration (com.jayway.jsonpath.Configuration)2 DocumentContext (com.jayway.jsonpath.DocumentContext)2 JsonPath (com.jayway.jsonpath.JsonPath)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1