diff --git a/.gitignore b/.gitignore index 7fd04a4c..88c91660 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ TODO gradle.properties build bin/ +out/ diff --git a/README.md b/README.md index f9059332..90826ee2 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Jayway JsonPath [![Build Status](https://travis-ci.org/json-path/JsonPath.svg?branch=master)](https://travis-ci.org/json-path/JsonPath) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.jayway.jsonpath/json-path/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.jayway.jsonpath/json-path) -[![Javadoc](https://javadoc-emblem.rhcloud.com/doc/com.jayway.jsonpath/json-path/badge.svg)](http://www.javadoc.io/doc/com.jayway.jsonpath/json-path) +[![Javadoc](https://www.javadoc.io/badge/com.jayway.jsonpath/json-path.svg)](http://www.javadoc.io/doc/com.jayway.jsonpath/json-path) Jayway JsonPath is a Java port of [Stefan Goessner JsonPath implementation](http://goessner.net/articles/JsonPath/). @@ -77,13 +77,13 @@ Functions Functions can be invoked at the tail end of a path - the input to a function is the output of the path expression. The function output is dictated by the function itself. -| Function | Description | Output | -| :------------------------ | :------------------------------------------------------------------ |-----------| -| min() | Provides the min value of an array of numbers | Double | -| max() | Provides the max value of an array of numbers | Double | -| avg() | Provides the average value of an array of numbers | Double | -| stddev() | Provides the standard deviation value of an array of numbers | Double | -| length() | Provides the length of an array | Integer | +| Function | Description | Output | +| :------------------------ | :----------------------------------------------------------------- |-----------| +| min() | Provides the min value of an array of numbers | Double | +| max() | Provides the max value of an array of numbers | Double | +| avg() | Provides the average value of an array of numbers | Double | +| stddev() | Provides the standard deviation value of an array of numbers | Double | +| length() | Provides the length of an array | Integer | Filter Operators @@ -91,22 +91,20 @@ Filter Operators Filters are logical expressions used to filter arrays. A typical filter would be `[?(@.age > 18)]` where `@` represents the current item being processed. More complex filters can be created with logical operators `&&` and `||`. String literals must be enclosed by single or double quotes (`[?(@.color == 'blue')]` or `[?(@.color == "blue")]`). -| Operator | Description | -| :----------------------- | :-------------------------------------------------------------------- | -| == | left is equal to right (note that 1 is not equal to '1') | -| != | left is not equal to right | -| < | left is less than right | -| <= | left is less or equal to right | -| > | left is greater than right | -| >= | left is greater than or equal to right | -| =~ | left matches regular expression [?(@.name =~ /foo.*?/i)] | -| in | left exists in right [?(@.size in ['S', 'M'])] | -| nin | left does not exists in right | -| subsetof | left is a subset of right [?(@.sizes subsetof ['S', 'M', 'L'])] | -| anyof | left has an intersection with right [?(@.sizes anyof ['M', 'L'])] | -| noneof | left has no intersection with right [?(@.sizes noneof ['M', 'L'])] | -| size | size of left (array or string) should match right | -| empty | left (array or string) should be empty | +| Operator | Description | +| :----------------------- | :---------------------------------------------------------------- | +| == | left is equal to right (note that 1 is not equal to '1') | +| != | left is not equal to right | +| < | left is less than right | +| <= | left is less or equal to right | +| > | left is greater than right | +| >= | left is greater than or equal to right | +| =~ | left matches regular expression [?(@.name =~ /foo.*?/i)] | +| in | left exists in right [?(@.size in ['S', 'M'])] | +| nin | left does not exists in right | +| subsetof | left is a subset of right [?(@.sizes subsetof ['S', 'M', 'L'])] | +| size | size of left (array or string) should match right | +| empty | left (array or string) should be empty | Path Examples @@ -241,7 +239,7 @@ String json = "{\"date_as_long\" : 1411455611975}"; Date date = JsonPath.parse(json).read("$['date_as_long']", Date.class); ``` -If you configure JsonPath to use `JacksonMappingProvider` or GsonMappingProvider` you can even map your JsonPath output directly into POJO's. +If you configure JsonPath to use `JacksonMappingProvider` or `GsonMappingProvider` you can even map your JsonPath output directly into POJO's. ```java Book book = JsonPath.parse(json).read("$.store.book[0]", Book.class); @@ -324,7 +322,7 @@ List> books = Path vs Value ------------- -In the Goessner implementation a JsonPath can return either `Path` or `Value`. `Value` is the default and what all the examples above are returning. If you rather have the path of the elements our query is hitting this can be acheived with an option. +In the Goessner implementation a JsonPath can return either `Path` or `Value`. `Value` is the default and what all the examples above are returning. If you rather have the path of the elements our query is hitting this can be achieved with an option. ```java Configuration conf = Configuration.builder() @@ -400,7 +398,7 @@ This option makes sure no exceptions are propagated from path evaluation. It fol ### JsonProvider SPI -JsonPath is shipped with three different JsonProviders: +JsonPath is shipped with five different JsonProviders: * [JsonSmartJsonProvider](https://code.google.com/p/json-smart/) (default) * [JacksonJsonProvider](https://github.com/FasterXML/jackson) diff --git a/build.gradle b/build.gradle index 2778e719..52c4963f 100644 --- a/build.gradle +++ b/build.gradle @@ -4,24 +4,31 @@ buildscript { } dependencies { classpath 'me.champeau.gradle:gradle-javadoc-hotfix-plugin:0.1' - classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3' classpath 'me.champeau.gradle:japicmp-gradle-plugin:0.1.0' + classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3' } } ext { libs = [ - slf4jApi: 'org.slf4j:slf4j-api:1.7.25', - jsonSmart: 'net.minidev:json-smart:2.3', - jacksonDatabind: 'com.fasterxml.jackson.core:jackson-databind:2.6.3', - gson: 'com.google.code.gson:gson:2.3.1', - jettison: 'org.codehaus.jettison:jettison:1.3.7', - jsonOrg: 'org.json:json:20140107', - tapestryJson: 'org.apache.tapestry:tapestry-json:5.4.3', + gson: 'com.google.code.gson:gson:2.8.5', hamcrestCore: 'org.hamcrest:hamcrest-core:1.3', hamcrestLibrary: 'org.hamcrest:hamcrest-library:1.3', + jacksonDatabind: 'com.fasterxml.jackson.core:jackson-databind:2.9.8', + jettison: 'org.codehaus.jettison:jettison:1.3.7', + jsonOrg: 'org.json:json:20140107', + jsonSmart: 'net.minidev:json-smart:2.3', + slf4jApi: 'org.slf4j:slf4j-api:1.7.26', + tapestryJson: 'org.apache.tapestry:tapestry-json:5.4.4', - test: ['org.slf4j:slf4j-simple:1.7.16', 'org.assertj:assertj-core:2.1.0', 'commons-io:commons-io:2.4','org.hamcrest:hamcrest-core:1.3', 'org.hamcrest:hamcrest-library:1.3', 'junit:junit:4.12'] + test: [ + 'commons-io:commons-io:2.4', + 'junit:junit:4.12', + 'org.assertj:assertj-core:3.11.1', + 'org.hamcrest:hamcrest-core:1.3', + 'org.hamcrest:hamcrest-library:1.3', + 'org.slf4j:slf4j-simple:1.7.26' + ] ] snapshotVersion = false } @@ -45,8 +52,8 @@ subprojects { apply plugin: 'signing' apply plugin: 'osgi' - sourceCompatibility = 1.6 - targetCompatibility = 1.6 + sourceCompatibility = 1.8 + targetCompatibility = 1.8 repositories { mavenCentral() diff --git a/json-path-assert/src/main/java/com/jayway/jsonassert/JsonAsserter.java b/json-path-assert/src/main/java/com/jayway/jsonassert/JsonAsserter.java index 2a152fbb..e420fc9d 100644 --- a/json-path-assert/src/main/java/com/jayway/jsonassert/JsonAsserter.java +++ b/json-path-assert/src/main/java/com/jayway/jsonassert/JsonAsserter.java @@ -22,11 +22,11 @@ public interface JsonAsserter { JsonAsserter assertThat(String path, Matcher matcher); /** - * @param path - * @param matcher - * @param message - * @param - * @return + * @param path the json path specifying the value being compared + * @param matcher an expression, built of Matchers, specifying allowed values + * @param message the explanation message + * @param the static type that should be returned by the path + * @return this to allow fluent assertion chains */ JsonAsserter assertThat(String path, Matcher matcher, String message); diff --git a/json-path-assert/src/main/java/com/jayway/jsonpath/matchers/WithJsonPath.java b/json-path-assert/src/main/java/com/jayway/jsonpath/matchers/WithJsonPath.java index 73acaaad..ca570d33 100644 --- a/json-path-assert/src/main/java/com/jayway/jsonpath/matchers/WithJsonPath.java +++ b/json-path-assert/src/main/java/com/jayway/jsonpath/matchers/WithJsonPath.java @@ -38,7 +38,7 @@ public class WithJsonPath extends TypeSafeMatcher { @Override protected void describeMismatchSafely(ReadContext context, Description mismatchDescription) { try { - T value = jsonPath.read(context.json()); + T value = jsonPath.read(context.jsonString()); mismatchDescription .appendText("json path ") .appendValue(jsonPath.getPath()) diff --git a/json-path-assert/src/test/java/com/jayway/jsonpath/matchers/HasNoJsonPathTest.java b/json-path-assert/src/test/java/com/jayway/jsonpath/matchers/HasNoJsonPathTest.java index edd4ca9e..b463742d 100644 --- a/json-path-assert/src/test/java/com/jayway/jsonpath/matchers/HasNoJsonPathTest.java +++ b/json-path-assert/src/test/java/com/jayway/jsonpath/matchers/HasNoJsonPathTest.java @@ -8,6 +8,7 @@ import static org.junit.Assert.assertThat; public class HasNoJsonPathTest { private static final String JSON_STRING = "{" + + "\"none\": null," + "\"name\": \"Jessie\"" + "}"; @@ -21,6 +22,11 @@ public class HasNoJsonPathTest { assertThat(JSON_STRING, not(hasNoJsonPath("$.name"))); } + @Test + public void shouldNotMatchExplicitNull() { + assertThat(JSON_STRING, not(hasNoJsonPath("$.none"))); + } + @Test public void shouldBeDescriptive() { assertThat(hasNoJsonPath("$.name"), diff --git a/json-path/src/main/java/com/jayway/jsonpath/Configuration.java b/json-path/src/main/java/com/jayway/jsonpath/Configuration.java index 1a591ea8..dd59fd70 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/Configuration.java +++ b/json-path/src/main/java/com/jayway/jsonpath/Configuration.java @@ -18,12 +18,7 @@ import com.jayway.jsonpath.internal.DefaultsImpl; import com.jayway.jsonpath.spi.json.JsonProvider; import com.jayway.jsonpath.spi.mapper.MappingProvider; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.EnumSet; -import java.util.Set; +import java.util.*; import static com.jayway.jsonpath.internal.Utils.notNull; import static java.util.Arrays.asList; @@ -142,7 +137,7 @@ public class Configuration { /** * Creates a new configuration with the provided options. Options in this configuration are discarded. * @param options - * @return + * @return the new configuration instance */ public Configuration setOptions(Option... options) { return Configuration.builder().jsonProvider(jsonProvider).mappingProvider(mappingProvider).options(options).evaluationListener(evaluationListeners).build(); @@ -150,7 +145,7 @@ public class Configuration { /** * Returns the options used by this configuration - * @return + * @return the new configuration instance */ public Set