From 28388af0f3c597e790d7c0c1ea62f8a2b794e253 Mon Sep 17 00:00:00 2001 From: Kalle Stenflo Date: Tue, 11 Nov 2014 18:57:59 +0100 Subject: [PATCH] Renamed JacksonTreeJsonProvider. --- README.md | 3 ++- ....java => JacksonJsonNodeJsonProvider.java} | 6 ++--- .../java/com/jayway/jsonpath/BaseTest.java | 6 ++--- ...a => JacksonJsonNodeJsonProviderTest.java} | 22 +++++++++---------- .../com/jayway/jsonpath/JsonProviderTest.java | 10 ++++----- 5 files changed, 24 insertions(+), 23 deletions(-) rename json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/{JacksonTreeJsonProvider.java => JacksonJsonNodeJsonProvider.java} (97%) rename json-path/src/test/java/com/jayway/jsonpath/{JacksonTreeJsonProviderTest.java => JacksonJsonNodeJsonProviderTest.java} (67%) diff --git a/README.md b/README.md index b64461ad..d8613279 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,7 @@ When evaluating a path you need to understand the concept of when a path is `def * `?()` - an expression * `[, (, )]` - multiple array indexes -`Indefinite` paths always returns a list. +`Indefinite` paths always returns a list (as represented by current JsonProvider). By default a simple object mapper is provided by the MappingProvider SPI. This allows you to specify the return type you want and the MappingProvider will try to perform the mapping. In the example below mapping between `Long` and `Date` is demonstrated. @@ -338,6 +338,7 @@ JsonPath is shipped with three different JsonProviders: * [JsonSmartJsonProvider](https://code.google.com/p/json-smart/) (default) * [JacksonJsonProvider](https://github.com/FasterXML/jackson) +* [JacksonJsonNodeJsonProvider](https://github.com/FasterXML/jackson) * [GsonJsonProvider](https://code.google.com/p/google-gson/) (experimental) Changing the configuration defaults as demonstrated should only be done when your application is being initialized. Changes during runtime is strongly discouraged, especially in multi threaded applications. diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/JacksonTreeJsonProvider.java b/json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/JacksonJsonNodeJsonProvider.java similarity index 97% rename from json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/JacksonTreeJsonProvider.java rename to json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/JacksonJsonNodeJsonProvider.java index af98464f..50895658 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/JacksonTreeJsonProvider.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/JacksonJsonNodeJsonProvider.java @@ -19,7 +19,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; -public class JacksonTreeJsonProvider extends AbstractJsonProvider { +public class JacksonJsonNodeJsonProvider extends AbstractJsonProvider { private static final Logger logger = LoggerFactory.getLogger(JacksonJsonProvider.class); @@ -34,7 +34,7 @@ public class JacksonTreeJsonProvider extends AbstractJsonProvider { /** * Initialize the JacksonTreeJsonProvider with the default ObjectMapper and ObjectReader */ - public JacksonTreeJsonProvider() { + public JacksonJsonNodeJsonProvider() { this(defaultObjectMapper); } @@ -43,7 +43,7 @@ public class JacksonTreeJsonProvider extends AbstractJsonProvider { * * @param objectMapper the ObjectMapper to use */ - public JacksonTreeJsonProvider(ObjectMapper objectMapper) { + public JacksonJsonNodeJsonProvider(ObjectMapper objectMapper) { this.objectMapper = objectMapper; } diff --git a/json-path/src/test/java/com/jayway/jsonpath/BaseTest.java b/json-path/src/test/java/com/jayway/jsonpath/BaseTest.java index e0a448ee..680451ac 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/BaseTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/BaseTest.java @@ -2,8 +2,8 @@ package com.jayway.jsonpath; import com.jayway.jsonpath.internal.Path; import com.jayway.jsonpath.internal.spi.json.GsonJsonProvider; +import com.jayway.jsonpath.internal.spi.json.JacksonJsonNodeJsonProvider; import com.jayway.jsonpath.internal.spi.json.JacksonJsonProvider; -import com.jayway.jsonpath.internal.spi.json.JacksonTreeJsonProvider; import com.jayway.jsonpath.internal.spi.mapper.GsonMappingProvider; import com.jayway.jsonpath.internal.spi.mapper.JacksonMappingProvider; import com.jayway.jsonpath.internal.token.PredicateContextImpl; @@ -24,10 +24,10 @@ public class BaseTest { .jsonProvider(new JacksonJsonProvider()) .build(); - public static final Configuration JACKSON_TREE_CONFIGURATION = Configuration + public static final Configuration JACKSON_JSON_NODE_CONFIGURATION = Configuration .builder() .mappingProvider(new JacksonMappingProvider()) - .jsonProvider(new JacksonTreeJsonProvider()) + .jsonProvider(new JacksonJsonNodeJsonProvider()) .build(); public static final Configuration JSON_SMART_CONFIGURATION = Configuration.defaultConfiguration(); diff --git a/json-path/src/test/java/com/jayway/jsonpath/JacksonTreeJsonProviderTest.java b/json-path/src/test/java/com/jayway/jsonpath/JacksonJsonNodeJsonProviderTest.java similarity index 67% rename from json-path/src/test/java/com/jayway/jsonpath/JacksonTreeJsonProviderTest.java rename to json-path/src/test/java/com/jayway/jsonpath/JacksonJsonNodeJsonProviderTest.java index 568071fb..58cd1860 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JacksonTreeJsonProviderTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JacksonJsonNodeJsonProviderTest.java @@ -12,7 +12,7 @@ import java.util.List; import static com.jayway.jsonpath.JsonPath.using; import static org.assertj.core.api.Assertions.assertThat; -public class JacksonTreeJsonProviderTest extends BaseTest { +public class JacksonJsonNodeJsonProviderTest extends BaseTest { private static final String JSON = "[" + @@ -38,14 +38,14 @@ public class JacksonTreeJsonProviderTest extends BaseTest { @Test public void json_can_be_parsed() { - ObjectNode node = using(JACKSON_TREE_CONFIGURATION).parse(JSON_DOCUMENT).read("$"); + ObjectNode node = using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON_DOCUMENT).read("$"); assertThat(node.get("string-property").asText()).isEqualTo("string-value"); } @Test public void strings_are_unwrapped() { - JsonNode node = using(JACKSON_TREE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.string-property"); - String unwrapped = using(JACKSON_TREE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.string-property", String.class); + JsonNode node = using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.string-property"); + String unwrapped = using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.string-property", String.class); assertThat(unwrapped).isEqualTo("string-value"); assertThat(unwrapped).isEqualTo(node.asText()); @@ -53,16 +53,16 @@ public class JacksonTreeJsonProviderTest extends BaseTest { @Test public void ints_are_unwrapped() { - JsonNode node = using(JACKSON_TREE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.int-max-property"); - int unwrapped = using(JACKSON_TREE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.int-max-property", int.class); + JsonNode node = using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.int-max-property"); + int unwrapped = using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.int-max-property", int.class); assertThat(unwrapped).isEqualTo(Integer.MAX_VALUE); assertThat(unwrapped).isEqualTo(node.asInt()); } @Test public void longs_are_unwrapped() { - JsonNode node = using(JACKSON_TREE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.long-max-property"); - long unwrapped = using(JACKSON_TREE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.long-max-property", long.class); + JsonNode node = using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.long-max-property"); + long unwrapped = using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.long-max-property", long.class); assertThat(unwrapped).isEqualTo(Long.MAX_VALUE); assertThat(unwrapped).isEqualTo(node.asLong()); @@ -71,7 +71,7 @@ public class JacksonTreeJsonProviderTest extends BaseTest { @Test public void list_of_numbers() { - ArrayNode objs = using(JACKSON_TREE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.store.book[*].display-price"); + ArrayNode objs = using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.store.book[*].display-price"); System.out.println(objs.toString()); } @@ -79,7 +79,7 @@ public class JacksonTreeJsonProviderTest extends BaseTest { public void test_type_ref() throws IOException { TypeRef>> typeRef = new TypeRef>>() {}; - List> list = using(JACKSON_TREE_CONFIGURATION).parse(JSON).read("$", typeRef); + List> list = using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON).read("$", typeRef); assertThat(list.get(0).gen.eric).isEqualTo("yepp"); } @@ -88,7 +88,7 @@ public class JacksonTreeJsonProviderTest extends BaseTest { public void test_type_ref_fail() throws IOException { TypeRef>> typeRef = new TypeRef>>() {}; - using(JACKSON_TREE_CONFIGURATION).parse(JSON).read("$", typeRef); + using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON).read("$", typeRef); } public static class FooBarBaz { diff --git a/json-path/src/test/java/com/jayway/jsonpath/JsonProviderTest.java b/json-path/src/test/java/com/jayway/jsonpath/JsonProviderTest.java index 67a118f2..9c80e56b 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JsonProviderTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JsonProviderTest.java @@ -35,7 +35,7 @@ public class JsonProviderTest extends BaseTest { @Test public void strings_are_unwrapped() { assertThat(using(JACKSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.string-property", String.class)).isEqualTo("string-value"); - assertThat(using(JACKSON_TREE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.string-property", String.class)).isEqualTo("string-value"); + assertThat(using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.string-property", String.class)).isEqualTo("string-value"); assertThat(using(JSON_SMART_CONFIGURATION).parse(JSON_DOCUMENT).read("$.string-property", String.class)).isEqualTo("string-value"); assertThat(using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.string-property", String.class)).isEqualTo("string-value"); } @@ -43,7 +43,7 @@ public class JsonProviderTest extends BaseTest { @Test public void integers_are_unwrapped() { assertThat(using(JACKSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.int-max-property", Integer.class)).isEqualTo(Integer.MAX_VALUE); - assertThat(using(JACKSON_TREE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.int-max-property", Integer.class)).isEqualTo(Integer.MAX_VALUE); + assertThat(using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.int-max-property", Integer.class)).isEqualTo(Integer.MAX_VALUE); assertThat(using(JSON_SMART_CONFIGURATION).parse(JSON_DOCUMENT).read("$.int-max-property", Integer.class)).isEqualTo(Integer.MAX_VALUE); assertThat(using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.int-max-property", Integer.class)).isEqualTo(Integer.MAX_VALUE); } @@ -51,7 +51,7 @@ public class JsonProviderTest extends BaseTest { @Test public void ints_are_unwrapped() { assertThat(using(JACKSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.int-max-property", int.class)).isEqualTo(Integer.MAX_VALUE); - assertThat(using(JACKSON_TREE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.int-max-property", int.class)).isEqualTo(Integer.MAX_VALUE); + assertThat(using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.int-max-property", int.class)).isEqualTo(Integer.MAX_VALUE); assertThat(using(JSON_SMART_CONFIGURATION).parse(JSON_DOCUMENT).read("$.int-max-property", int.class)).isEqualTo(Integer.MAX_VALUE); assertThat(using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.int-max-property", int.class)).isEqualTo(Integer.MAX_VALUE); } @@ -61,7 +61,7 @@ public class JsonProviderTest extends BaseTest { TypeRef> typeRef = new TypeRef>() {}; - assertThat(using(JACKSON_TREE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.store.book[*].display-price", typeRef)).containsExactly(8.95D, 12.99D, 8.99D, 22.99D); + assertThat(using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.store.book[*].display-price", typeRef)).containsExactly(8.95D, 12.99D, 8.99D, 22.99D); assertThat(using(JACKSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.store.book[*].display-price", typeRef)).containsExactly(8.95D, 12.99D, 8.99D, 22.99D); assertThat(using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.store.book[*].display-price", typeRef)).containsExactly(8.95D, 12.99D, 8.99D, 22.99D); } @@ -71,7 +71,7 @@ public class JsonProviderTest extends BaseTest { TypeRef>> typeRef = new TypeRef>>() {}; assertThat(using(JACKSON_CONFIGURATION).parse(JSON).read("$", typeRef)).extracting("foo").containsExactly("foo0", "foo1", "foo2"); - assertThat(using(JACKSON_TREE_CONFIGURATION).parse(JSON).read("$", typeRef)).extracting("foo").containsExactly("foo0", "foo1", "foo2"); + assertThat(using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON).read("$", typeRef)).extracting("foo").containsExactly("foo0", "foo1", "foo2"); assertThat(using(GSON_CONFIGURATION).parse(JSON).read("$", typeRef)).extracting("foo").containsExactly("foo0", "foo1", "foo2"); }