Skip to content

Commit

Permalink
Merge branch 'release/1.0.0-preview.20201123' into master/1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
eiiches committed Nov 23, 2020
2 parents 87a7931 + 0e0d277 commit 4585bc7
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 19 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ Usage

First, you need Java 8 or later.

If you use Maven, add the following snippet to the `<dependencies>` section of your POM. For instructions for other build tools (Gradle, etc.), visit [jackson-jq](https://search.maven.org/artifact/net.thisptr/jackson-jq/1.0.0-preview.20191208/jar) on search.maven.org.
If you use Maven, add the following snippet to the `<dependencies>` section of your POM. For instructions for other build tools (Gradle, etc.), visit [jackson-jq](https://search.maven.org/artifact/net.thisptr/jackson-jq/1.0.0-preview.20201123/jar) on search.maven.org.

```xml
<dependency>
<groupId>net.thisptr</groupId>
<artifactId>jackson-jq</artifactId>
<version>1.0.0-preview.20191208</version>
<version>1.0.0-preview.20201123</version>
</dependency>
```

Expand All @@ -30,29 +30,29 @@ Using a jackson-jq command line tool
To test a query quickly, we provide jackson-jq CLI.

```sh
$ curl -LO https://repo1.maven.org/maven2/net/thisptr/jackson-jq-cli/1.0.0-preview.20191208/jackson-jq-cli-1.0.0-preview.20191208.jar
$ curl -LO https://repo1.maven.org/maven2/net/thisptr/jackson-jq-cli/1.0.0-preview.20201123/jackson-jq-cli-1.0.0-preview.20201123.jar

$ java -jar jackson-jq-cli-1.0.0-preview.20191208.jar --help
$ java -jar jackson-jq-cli-1.0.0-preview.20201123.jar --help
usage: jackson-jq [OPTIONS...] QUERY
-c,--compact compact instead of pretty-printed output
-h,--help print this message
--jq <arg> specify jq version
-n,--null-input use `null` as the single input value
-r,--raw output raw strings, not JSON texts

$ java -jar jackson-jq-cli-1.0.0-preview.20191208.jar '.foo'
$ java -jar jackson-jq-cli-1.0.0-preview.20201123.jar '.foo'
{"foo": 42}
42
```

To test a query with a specific jq version,

```sh
$ java -jar jackson-jq-cli-1.0.0-preview.20191208.jar --jq 1.5 'join("-")'
$ java -jar jackson-jq-cli-1.0.0-preview.20201123.jar --jq 1.5 'join("-")'
["1", 2]
jq: error: string ("-") and number (2) cannot be added

$ java -jar jackson-jq-cli-1.0.0-preview.20191208.jar --jq 1.6 'join("-")' # jq-1.6 can join any values, not only strings
$ java -jar jackson-jq-cli-1.0.0-preview.20201123.jar --jq 1.6 'join("-")' # jq-1.6 can join any values, not only strings
["1", 2]
"1-2"
```
Expand Down Expand Up @@ -130,7 +130,7 @@ This table illustrates which features (picked from jq-1.5 manual) are supported
| &nbsp;&nbsp;&nbsp;&nbsp;&bull; [`unique`, `unique_by(path_exp)`](https://stedolan.github.io/jq/manual/v1.5/#unique&#44;unique&#95;by&#40;path&#95;exp&#41;) ||
| &nbsp;&nbsp;&nbsp;&nbsp;&bull; [`reverse`](https://stedolan.github.io/jq/manual/v1.5/#reverse) ||
| &nbsp;&nbsp;&nbsp;&nbsp;&bull; [`contains(element)`](https://stedolan.github.io/jq/manual/v1.5/#contains&#40;element&#41;) ||
| &nbsp;&nbsp;&nbsp;&nbsp;&bull; [`indices(s)`](https://stedolan.github.io/jq/manual/v1.5/#indices&#40;s&#41;) | |
| &nbsp;&nbsp;&nbsp;&nbsp;&bull; [`indices(s)`](https://stedolan.github.io/jq/manual/v1.5/#indices&#40;s&#41;) |<sup>*9</sup> |
| &nbsp;&nbsp;&nbsp;&nbsp;&bull; [`index(s)`, `rindex(s)`](https://stedolan.github.io/jq/manual/v1.5/#index&#40;s&#41;&#44;rindex&#40;s&#41;) ||
| &nbsp;&nbsp;&nbsp;&nbsp;&bull; [`inside`](https://stedolan.github.io/jq/manual/v1.5/#inside) ||
| &nbsp;&nbsp;&nbsp;&nbsp;&bull; [`startswith(str)`](https://stedolan.github.io/jq/manual/v1.5/#startswith&#40;str&#41;) ||
Expand Down Expand Up @@ -224,6 +224,8 @@ This table illustrates which features (picked from jq-1.5 manual) are supported

*8) `.foo |= empty` always throws an error in jackson-jq instead of producing an unexpected result. jq-1.5 and jq-1.6 respectively produces a different and incorrect result for `[1,2,3] | ((.[] | select(. > 1)) |= empty)`. [jq#897](https://github.com/stedolan/jq/issues/897) says "empty in the RHS is undefined". You can still use `_modify/2` directly if you really want to emulate the exact jq-1.5 or jq-1.6 behavior.

*9) `"x" | indices("")` always returns an empty array in jackson-jq. The behavior is in line with jq after [2660b04](https://github.com/stedolan/jq/commit/2660b04a731568c54eb4b91fe811d81cbbf3470b) commit, but differs from how jq-1.5 and jq-1.6 behave.

Using jackson-jq-extra module
-----------------------------

Expand All @@ -233,7 +235,7 @@ Using jackson-jq-extra module
<dependency>
<groupId>net.thisptr</groupId>
<artifactId>jackson-jq-extra</artifactId>
<version>1.0.0-preview.20191208</version>
<version>1.0.0-preview.20201123</version>
</dependency>
```

Expand Down
4 changes: 2 additions & 2 deletions jackson-jq-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
<parent>
<groupId>net.thisptr</groupId>
<artifactId>jackson-jq-parent</artifactId>
<version>1.0.0-preview.20191208</version>
<version>1.0.0-preview.20201123</version>
</parent>

<dependencies>
<dependency>
<groupId>net.thisptr</groupId>
<artifactId>jackson-jq-extra</artifactId>
<version>1.0.0-preview.20191208</version>
<version>1.0.0-preview.20201123</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
Expand Down
4 changes: 2 additions & 2 deletions jackson-jq-extra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
<parent>
<groupId>net.thisptr</groupId>
<artifactId>jackson-jq-parent</artifactId>
<version>1.0.0-preview.20191208</version>
<version>1.0.0-preview.20201123</version>
</parent>

<dependencies>
<dependency>
<groupId>net.thisptr</groupId>
<artifactId>jackson-jq</artifactId>
<version>1.0.0-preview.20191208</version>
<version>1.0.0-preview.20201123</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion jackson-jq/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>net.thisptr</groupId>
<artifactId>jackson-jq-parent</artifactId>
<version>1.0.0-preview.20191208</version>
<version>1.0.0-preview.20201123</version>
</parent>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ public static List<Integer> indices(final JsonNode needle, final JsonNode haysta
if (needle.isTextual() && haystack.isTextual()) {
final String haystackText = haystack.asText();
final String needleText = needle.asText();
for (int index = haystackText.indexOf(needleText); index >= 0; index = haystackText.indexOf(needleText, index + 1))
result.add(index);
if (!needleText.isEmpty()) {
for (int index = haystackText.indexOf(needleText); index >= 0; index = haystackText.indexOf(needleText, index + 1))
result.add(index);
}
} else if (needle.isArray() && haystack.isArray()) {
if (needle.size() != 0) {
for (int i = 0; i < haystack.size(); ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public static class TestCase {
@JsonProperty("should_compile")
public boolean shouldCompile = true;

@JsonProperty("ignore_true_jq_behavior")
public boolean ignoreTrueJqBehavior = false;

@JsonInclude(Include.NON_NULL)
@JsonProperty("v")
@JsonDeserialize(using = VersionRangeDeserializer.class)
Expand Down Expand Up @@ -156,7 +159,7 @@ private void test(final TestCase tc, final Version version) throws Throwable {
return;
}

if (hasJqCache.computeIfAbsent(version, v -> TrueJqEvaluator.hasJq(v))) {
if (!tc.ignoreTrueJqBehavior && hasJqCache.computeIfAbsent(version, v -> TrueJqEvaluator.hasJq(v))) {
final Result result = cachedJqEvaluator.evaluate(tc.q, tc.in, version, 2000L);
assumeThat(result.error).as("%s", command).isNull();
assumeThat(wrap(tc.out)).as("%s", command).isEqualTo(wrap(result.values));
Expand Down
1 change: 1 addition & 0 deletions jackson-jq/src/test/resources/tests/functions/indices.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- {"v":"[1.5,1.5]","q":"indices(-1.0)","in":null,"out":[null]}
- {"v":"[1.5,1.6]","q":"indices(\"\")","in":"x","out":[[]],"ignore_true_jq_behavior":true}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>net.thisptr</groupId>
<artifactId>jackson-jq-parent</artifactId>
<packaging>pom</packaging>
<version>1.0.0-preview.20191208</version>
<version>1.0.0-preview.20201123</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>jq for Jackson JSON Processor</description>
<url>https://github.com/eiiches/jackson-jq</url>
Expand All @@ -28,7 +28,7 @@
<connection>scm:git:[email protected]:eiiches/jackson-jq.git</connection>
<developerConnection>scm:git:[email protected]:eiiches/jackson-jq.git</developerConnection>
<url>[email protected]:juven/git-demo.git</url>
<tag>1.0.0-preview.20191208</tag>
<tag>1.0.0-preview.20201123</tag>
</scm>

<modules>
Expand Down

0 comments on commit 4585bc7

Please sign in to comment.