Skip to content

Commit d373805

Browse files
committed
Merge branch 'release/1.0.0-preview.20210610' into master/1.x
2 parents 4585bc7 + 2a0a4e7 commit d373805

15 files changed

Lines changed: 216 additions & 60 deletions

File tree

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ Usage
1212

1313
First, you need Java 8 or later.
1414

15-
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.
15+
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.20210610/jar) on search.maven.org.
1616

1717
```xml
1818
<dependency>
1919
<groupId>net.thisptr</groupId>
2020
<artifactId>jackson-jq</artifactId>
21-
<version>1.0.0-preview.20201123</version>
21+
<version>1.0.0-preview.20210610</version>
2222
</dependency>
2323
```
2424

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

3232
```sh
33-
$ 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
33+
$ curl -LO https://repo1.maven.org/maven2/net/thisptr/jackson-jq-cli/1.0.0-preview.20210610/jackson-jq-cli-1.0.0-preview.20210610.jar
3434

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

43-
$ java -jar jackson-jq-cli-1.0.0-preview.20201123.jar '.foo'
43+
$ java -jar jackson-jq-cli-1.0.0-preview.20210610.jar '.foo'
4444
{"foo": 42}
4545
42
4646
```
4747

4848
To test a query with a specific jq version,
4949

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

55-
$ 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
55+
$ java -jar jackson-jq-cli-1.0.0-preview.20210610.jar --jq 1.6 'join("-")' # jq-1.6 can join any values, not only strings
5656
["1", 2]
5757
"1-2"
5858
```
@@ -235,7 +235,7 @@ Using jackson-jq-extra module
235235
<dependency>
236236
<groupId>net.thisptr</groupId>
237237
<artifactId>jackson-jq-extra</artifactId>
238-
<version>1.0.0-preview.20201123</version>
238+
<version>1.0.0-preview.20210610</version>
239239
</dependency>
240240
```
241241

jackson-jq-cli/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
<parent>
99
<groupId>net.thisptr</groupId>
1010
<artifactId>jackson-jq-parent</artifactId>
11-
<version>1.0.0-preview.20201123</version>
11+
<version>1.0.0-preview.20210610</version>
1212
</parent>
1313

1414
<dependencies>
1515
<dependency>
1616
<groupId>net.thisptr</groupId>
1717
<artifactId>jackson-jq-extra</artifactId>
18-
<version>1.0.0-preview.20201123</version>
18+
<version>1.0.0-preview.20210610</version>
1919
</dependency>
2020
<dependency>
2121
<groupId>commons-cli</groupId>

jackson-jq-extra/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
<parent>
99
<groupId>net.thisptr</groupId>
1010
<artifactId>jackson-jq-parent</artifactId>
11-
<version>1.0.0-preview.20201123</version>
11+
<version>1.0.0-preview.20210610</version>
1212
</parent>
1313

1414
<dependencies>
1515
<dependency>
1616
<groupId>net.thisptr</groupId>
1717
<artifactId>jackson-jq</artifactId>
18-
<version>1.0.0-preview.20201123</version>
18+
<version>1.0.0-preview.20210610</version>
1919
</dependency>
2020
</dependencies>
2121

jackson-jq/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<parent>
99
<groupId>net.thisptr</groupId>
1010
<artifactId>jackson-jq-parent</artifactId>
11-
<version>1.0.0-preview.20201123</version>
11+
<version>1.0.0-preview.20210610</version>
1212
</parent>
1313

1414
<dependencies>
@@ -20,7 +20,7 @@
2020
<dependency>
2121
<groupId>com.google.guava</groupId>
2222
<artifactId>guava</artifactId>
23-
<version>28.1-jre</version>
23+
<version>30.1.1-jre</version>
2424
<scope>test</scope>
2525
</dependency>
2626
<dependency>

jackson-jq/src/main/java/net/thisptr/jackson/jq/internal/misc/Pair.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,36 @@ public static <T, U> List<U> _2(final List<Pair<T, U>> items) {
3434
public String toString() {
3535
return String.format("(%s, %s)", _1, _2);
3636
}
37+
38+
@Override
39+
public int hashCode() {
40+
final int prime = 31;
41+
int result = 1;
42+
result = prime * result + ((_1 == null) ? 0 : _1.hashCode());
43+
result = prime * result + ((_2 == null) ? 0 : _2.hashCode());
44+
return result;
45+
}
46+
47+
@Override
48+
public boolean equals(final Object obj) {
49+
if (this == obj)
50+
return true;
51+
if (obj == null)
52+
return false;
53+
if (getClass() != obj.getClass())
54+
return false;
55+
@SuppressWarnings("rawtypes")
56+
final Pair other = (Pair) obj;
57+
if (_1 == null) {
58+
if (other._1 != null)
59+
return false;
60+
} else if (!_1.equals(other._1))
61+
return false;
62+
if (_2 == null) {
63+
if (other._2 != null)
64+
return false;
65+
} else if (!_2.equals(other._2))
66+
return false;
67+
return true;
68+
}
3769
}

jackson-jq/src/main/java/net/thisptr/jackson/jq/internal/tree/ForeachExpression.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void apply(final Scope scope, final JsonNode in, final Path ipath, final
5555
accumulators[0] = newaccumulator;
5656
accumulatorPaths[0] = newaccumulatorPath;
5757
}, extractExpr != null ? false : requirePath);
58-
}, stack, true);
58+
}, stack);
5959
}, requirePath);
6060
}, false);
6161
}

jackson-jq/src/main/java/net/thisptr/jackson/jq/internal/tree/PipedQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private static void pathRecursive(final Scope scope, final JsonNode in, final Pa
4646
childScope.setValueWithPath(var.name, var.value, var.path);
4747
}
4848
pathRecursive(childScope, in, path, output, tail, requirePath);
49-
}, accumulate, true);
49+
}, accumulate);
5050
});
5151
} else if (head instanceof TransformPipeComponent) {
5252
((TransformPipeComponent) head).expr.apply(scope, in, path, (pobj, ppath) -> {

jackson-jq/src/main/java/net/thisptr/jackson/jq/internal/tree/ReduceExpression.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void apply(final Scope scope, final JsonNode in, final Path ipath, final
4949
final List<JsonNode> reduceResult = new ArrayList<>();
5050
reduceExpr.apply(childScope, accumulators[0], reduceResult::add);
5151
accumulators[0] = reduceResult.isEmpty() ? NullNode.getInstance() : reduceResult.get(reduceResult.size() - 1);
52-
}, stack, true);
52+
}, stack);
5353
});
5454

5555
output.emit(accumulators[0], null);

jackson-jq/src/main/java/net/thisptr/jackson/jq/internal/tree/matcher/PatternMatcher.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
import net.thisptr.jackson.jq.path.Path;
1313

1414
public interface PatternMatcher {
15-
16-
void match(final Scope scope, final JsonNode in, final Functional.Consumer<List<Pair<String, JsonNode>>> out, final Stack<Pair<String, JsonNode>> accumulate, final boolean emit) throws JsonQueryException;
15+
void match(final Scope scope, final JsonNode in, final Functional.Consumer<List<Pair<String, JsonNode>>> out, final Stack<Pair<String, JsonNode>> accumulate) throws JsonQueryException;
1716

1817
public static class MatchWithPath {
1918
public final String name;
@@ -31,5 +30,5 @@ public interface MatchOutput {
3130
void emit(List<MatchWithPath> vars) throws JsonQueryException;
3231
}
3332

34-
void matchWithPath(Scope scope, JsonNode in, Path path, MatchOutput output, Stack<MatchWithPath> accumulate, boolean emit) throws JsonQueryException;
33+
void matchWithPath(Scope scope, JsonNode in, Path path, MatchOutput output, Stack<MatchWithPath> accumulate) throws JsonQueryException;
3534
}

jackson-jq/src/main/java/net/thisptr/jackson/jq/internal/tree/matcher/matchers/ArrayMatcher.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,47 @@ public ArrayMatcher(final List<PatternMatcher> matchers) {
2222
this.matchers = matchers;
2323
}
2424

25+
private void recursive(final Scope scope, final JsonNode in, final Functional.Consumer<List<Pair<String, JsonNode>>> out, final Stack<Pair<String, JsonNode>> accumulate, int index) throws JsonQueryException {
26+
if (index >= matchers.size()) {
27+
out.accept(accumulate);
28+
return;
29+
}
30+
31+
final PatternMatcher matcher = matchers.get(index);
32+
final JsonNode value = in.get(index);
33+
34+
matcher.match(scope, value != null ? value : NullNode.getInstance(), (match) -> {
35+
recursive(scope, in, out, accumulate, index + 1);
36+
}, accumulate);
37+
}
38+
2539
@Override
26-
public void match(final Scope scope, final JsonNode in, final Functional.Consumer<List<Pair<String, JsonNode>>> out, final Stack<Pair<String, JsonNode>> accumulate, final boolean emit) throws JsonQueryException {
40+
public void match(final Scope scope, final JsonNode in, final Functional.Consumer<List<Pair<String, JsonNode>>> out, final Stack<Pair<String, JsonNode>> accumulate) throws JsonQueryException {
2741
if (!in.isArray() && !in.isNull())
2842
throw new JsonQueryTypeException("Cannot index %s with number", in.getNodeType());
29-
for (int i = 0; i < matchers.size(); ++i) {
30-
final PatternMatcher matcher = matchers.get(i);
31-
final JsonNode item = in.get(i);
32-
matcher.match(scope, item != null ? item : NullNode.getInstance(), out, accumulate, emit && i == matchers.size() - 1);
43+
recursive(scope, in, out, accumulate, 0);
44+
}
45+
46+
private void recursiveWithPath(final Scope scope, final JsonNode in, final Path path, final MatchOutput out, final Stack<MatchWithPath> accumulate, int index) throws JsonQueryException {
47+
if (index >= matchers.size()) {
48+
out.emit(accumulate);
49+
return;
3350
}
51+
52+
final PatternMatcher matcher = matchers.get(index);
53+
final JsonNode value = in.get(index);
54+
final ArrayIndexPath valuePath = ArrayIndexPath.chainIfNotNull(path, index);
55+
56+
matcher.matchWithPath(scope, value != null ? value : NullNode.getInstance(), valuePath, (match) -> {
57+
recursiveWithPath(scope, in, path, out, accumulate, index + 1);
58+
}, accumulate);
3459
}
3560

3661
@Override
37-
public void matchWithPath(final Scope scope, final JsonNode in, final Path path, final MatchOutput output, final Stack<MatchWithPath> accumulate, final boolean emit) throws JsonQueryException {
62+
public void matchWithPath(final Scope scope, final JsonNode in, final Path path, final MatchOutput out, final Stack<MatchWithPath> accumulate) throws JsonQueryException {
3863
if (!in.isArray() && !in.isNull())
3964
throw new JsonQueryTypeException("Cannot index %s with number", in.getNodeType());
40-
for (int i = 0; i < matchers.size(); ++i) {
41-
final PatternMatcher matcher = matchers.get(i);
42-
final JsonNode item = in.get(i);
43-
matcher.matchWithPath(scope, item != null ? item : NullNode.getInstance(), ArrayIndexPath.chainIfNotNull(path, i), output, accumulate, emit && i == matchers.size() - 1);
44-
}
65+
recursiveWithPath(scope, in, path, out, accumulate, 0);
4566
}
4667

4768
@Override

0 commit comments

Comments
 (0)