Skip to content

Commit b6fc733

Browse files
committed
Merge branch 'release/1.0.0-preview.20210928' into master/1.x
2 parents 5186c99 + e65215d commit b6fc733

42 files changed

Lines changed: 1306 additions & 73 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 38 additions & 26 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.20210926/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.20210928/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.20210926</version>
21+
<version>1.0.0-preview.20210928</version>
2222
</dependency>
2323
```
2424

@@ -32,29 +32,29 @@ To test a query quickly, we provide jackson-jq CLI.
3232
*Please note that jackson-jq is a Java library and the CLI is provided solely for debugging/testing purpose (and not for production). The command-line options might change without notice.*
3333

3434
```sh
35-
$ curl -LO https://repo1.maven.org/maven2/net/thisptr/jackson-jq-cli/1.0.0-preview.20210926/jackson-jq-cli-1.0.0-preview.20210926.jar
35+
$ curl -LO https://repo1.maven.org/maven2/net/thisptr/jackson-jq-cli/1.0.0-preview.20210928/jackson-jq-cli-1.0.0-preview.20210928.jar
3636

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

45-
$ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar '.foo'
45+
$ java -jar jackson-jq-cli-1.0.0-preview.20210928.jar '.foo'
4646
{"foo": 42}
4747
42
4848
```
4949

5050
To test a query with a specific jq version,
5151

5252
```sh
53-
$ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar --jq 1.5 'join("-")'
53+
$ java -jar jackson-jq-cli-1.0.0-preview.20210928.jar --jq 1.5 'join("-")'
5454
["1", 2]
5555
jq: error: string ("-") and number (2) cannot be added
5656

57-
$ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar --jq 1.6 'join("-")' # jq-1.6 can join any values, not only strings
57+
$ java -jar jackson-jq-cli-1.0.0-preview.20210928.jar --jq 1.6 'join("-")' # jq-1.6 can join any values, not only strings
5858
["1", 2]
5959
"1-2"
6060
```
@@ -206,7 +206,7 @@ This table illustrates which features (picked from jq-1.5 manual) are supported
206206
| &nbsp;&nbsp;&nbsp;&nbsp;&bull; [`ǀ=`](https://stedolan.github.io/jq/manual/v1.5/#&#124;&#61;) | ○<sup>*8</sup> |
207207
| &nbsp;&nbsp;&nbsp;&nbsp;&bull; [`+=`, `-=`, `*=`, `/=`, `%=`, `//=`](https://stedolan.github.io/jq/manual/v1.5/#&#43;&#61;&#44;&#45;&#61;&#44;&#42;&#61;&#44;&#47;&#61;&#44;&#37;&#61;&#44;&#47;&#47;&#61;) ||
208208
| &nbsp;&nbsp;&nbsp;&nbsp;&bull; [Complex assignments](https://stedolan.github.io/jq/manual/v1.5/#Complexassignments) ||
209-
| [Modules](https://stedolan.github.io/jq/manual/v1.5/#Modules) | × |
209+
| [Modules](https://stedolan.github.io/jq/manual/v1.5/#Modules) | |
210210
| &nbsp;&nbsp;&nbsp;&nbsp;&bull; [`import RelativePathString as NAME [<metadata>];`](https://stedolan.github.io/jq/manual/v1.5/#importRelativePathStringasNAME&#91;&#60;metadata&#62;&#93;&#59;) | × |
211211
| &nbsp;&nbsp;&nbsp;&nbsp;&bull; [`include RelativePathString [<metadata>];`](https://stedolan.github.io/jq/manual/v1.5/#includeRelativePathString&#91;&#60;metadata&#62;&#93;&#59;) | × |
212212
| &nbsp;&nbsp;&nbsp;&nbsp;&bull; [`import RelativePathString as $NAME [<metadata>];`](https://stedolan.github.io/jq/manual/v1.5/#importRelativePathStringas&#36;NAME&#91;&#60;metadata&#62;&#93;&#59;) | × |
@@ -236,9 +236,9 @@ $ jq -n '1 + 3 as $a | ($a * 2)' # interpreted as 1 + (3 as $a | ($a * 2))
236236
whereas jackson-jq consistently interprets them as `(1 + 3)` whether `as $a` is used or not:
237237

238238
```console
239-
$ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar -n '1 + 3 | (. * 2)' # interpreted as (1 + 3) | (. * 2)
239+
$ java -jar jackson-jq-cli-1.0.0-preview.20210928.jar -n '1 + 3 | (. * 2)' # interpreted as (1 + 3) | (. * 2)
240240
8
241-
$ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar -n '1 + 3 as $a | ($a * 2)' # interpreted as (1 + 3) as $a | ($a * 2)
241+
$ java -jar jackson-jq-cli-1.0.0-preview.20210928.jar -n '1 + 3 as $a | ($a * 2)' # interpreted as (1 + 3) as $a | ($a * 2)
242242
8
243243
```
244244

@@ -247,7 +247,7 @@ $ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar -n '1 + 3 as $a | ($a * 2)
247247
```console
248248
$ jq -n '1 + 3 as $a | ($a * 2)' # interpreted as 1 + (3 as $a | ($a * 2))
249249
7
250-
$ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar -n '1 + 3 as $a | ($a * 2)' # interpreted as (1 + 3) as $a | ($a * 2)
250+
$ java -jar jackson-jq-cli-1.0.0-preview.20210928.jar -n '1 + 3 as $a | ($a * 2)' # interpreted as (1 + 3) as $a | ($a * 2)
251251
8
252252
```
253253

@@ -274,7 +274,7 @@ If the function with the same is defined more than once at the same scope, jacks
274274
```console
275275
$ jq -n 'def f: 1; def g: f; def f: 2; g'
276276
1
277-
$ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar -n 'def f: 1; def g: f; def f: 2; g'
277+
$ java -jar jackson-jq-cli-1.0.0-preview.20210928.jar -n 'def f: 1; def g: f; def f: 2; g'
278278
2
279279
```
280280

@@ -283,7 +283,7 @@ $ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar -n 'def f: 1; def g: f; de
283283
Avoid using the duplicate function name.
284284

285285
```console
286-
$ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar -n 'def f1: 1; def g: f1; def f2: 2; g'
286+
$ java -jar jackson-jq-cli-1.0.0-preview.20210928.jar -n 'def f1: 1; def g: f1; def f2: 2; g'
287287
1
288288
```
289289

@@ -353,7 +353,7 @@ jq: error: Division by zero? at <top-level>, line 1:
353353
jq: 1 compile error
354354
$ jq '. / 0' <<< 0
355355
jq: error (at <stdin>:1): number (0) and number (0) cannot be divided because the divisor is zero
356-
$ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar -n '0 / 0'
356+
$ java -jar jackson-jq-cli-1.0.0-preview.20210928.jar -n '0 / 0'
357357
jq: error: number (0) and number (0) cannot be divided because the divisor is zero
358358
```
359359

@@ -386,9 +386,9 @@ $ jq-1.2 -n '[1,2,3] | ((.[] | select(. > 1)) |= empty)'
386386
2,
387387
3
388388
]
389-
$ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar --jq 1.6 -n '[1,2,3] | ((.[] | select(. > 1)) |= empty)'
389+
$ java -jar jackson-jq-cli-1.0.0-preview.20210928.jar --jq 1.6 -n '[1,2,3] | ((.[] | select(. > 1)) |= empty)'
390390
jq: error: `|= empty` is undefined. See https://github.com/stedolan/jq/issues/897
391-
$ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar --jq 1.5 -n '[1,2,3] | ((.[] | select(. > 1)) |= empty)'
391+
$ java -jar jackson-jq-cli-1.0.0-preview.20210928.jar --jq 1.5 -n '[1,2,3] | ((.[] | select(. > 1)) |= empty)'
392392
jq: error: `|= empty` is undefined. See https://github.com/stedolan/jq/issues/897
393393
```
394394

@@ -397,9 +397,9 @@ jq: error: `|= empty` is undefined. See https://github.com/stedolan/jq/issues/89
397397
You can use `_modify/2` if you really want to the original behavior.
398398

399399
```console
400-
$ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar --jq 1.6 -n '[1,2,3] | _modify((.[] | select(. > 1)); empty)'
400+
$ java -jar jackson-jq-cli-1.0.0-preview.20210928.jar --jq 1.6 -n '[1,2,3] | _modify((.[] | select(. > 1)); empty)'
401401
[ 1, 3 ]
402-
$ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar --jq 1.5 -n '[1,2,3] | _modify((.[] | select(. > 1)); empty)'
402+
$ java -jar jackson-jq-cli-1.0.0-preview.20210928.jar --jq 1.5 -n '[1,2,3] | _modify((.[] | select(. > 1)); empty)'
403403
null
404404
```
405405

@@ -419,7 +419,7 @@ jq 1.5
419419
```console
420420
$ jq-1.5 -c 'path(.foo as $a | $a)' <<< '{"foo": 1}'
421421
["foo"]
422-
$ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar --jq 1.5 -c 'path(.foo as $a | $a)' <<< '{"foo": 1}'
422+
$ java -jar jackson-jq-cli-1.0.0-preview.20210928.jar --jq 1.5 -c 'path(.foo as $a | $a)' <<< '{"foo": 1}'
423423
jq: error: Invalid path expression with result 1
424424
```
425425

@@ -428,7 +428,7 @@ jq 1.6
428428
```console
429429
$ jq-1.6 -c 'path(.foo as $a | $a)' <<< '{"foo": 1}'
430430
jq: error (at <stdin>:1): Invalid path expression with result 1
431-
$ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar --jq 1.6 -c 'path(.foo as $a | $a)' <<< '{"foo": 1}'
431+
$ java -jar jackson-jq-cli-1.0.0-preview.20210928.jar --jq 1.6 -c 'path(.foo as $a | $a)' <<< '{"foo": 1}'
432432
jq: error: Invalid path expression with result 1
433433
```
434434

@@ -452,7 +452,7 @@ $ jq -n 'label $a | label $b | try (break $b) catch .'
452452
{
453453
"__jq": 1
454454
}
455-
$ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar -n 'label $a | label $b | try (break $b) catch .'
455+
$ java -jar jackson-jq-cli-1.0.0-preview.20210928.jar -n 'label $a | label $b | try (break $b) catch .'
456456
{
457457
"__jq" : 0
458458
}
@@ -482,25 +482,37 @@ $ jq-1.6 -n '"x" | indices("")' # stuck in infinite loop
482482
^C
483483
$ jq-1.6-83-gb52fc10 -n '"x" | indices("")'
484484
[]
485-
$ java -jar jackson-jq-cli-1.0.0-preview.20210926.jar -n '"x" | indices("")'
485+
$ java -jar jackson-jq-cli-1.0.0-preview.20210928.jar -n '"x" | indices("")'
486486
[ ]
487487
```
488488

489489
</details>
490490

491-
Using jackson-jq-extra module
492-
-----------------------------
491+
Using jackson-jq/extras module
492+
------------------------------
493493

494-
`jackson-jq-extra` module provides extra functions that you might find useful. These functions do not exist in jq.
494+
The `jackson-jq/extras` module is a jq module that provides some useful functions that do not exist in jq.
495+
496+
To use this module, you need to add the following Maven dependency and set `BuiltinModuleLoader` (see [jackson-jq/src/test/java/examples/Usage.java](jackson-jq/src/test/java/examples/Usage.java)) to the scope.
495497

496498
```xml
497499
<dependency>
498500
<groupId>net.thisptr</groupId>
499501
<artifactId>jackson-jq-extra</artifactId>
500-
<version>1.0.0-preview.20210926</version>
502+
<version>1.0.0-preview.20210928</version>
501503
</dependency>
502504
```
503505

506+
Now, you can import the module in jq:
507+
508+
```jq
509+
import "jackson-jq/extras" as extras;
510+
511+
extras::uuid4
512+
```
513+
514+
For a historical reason, adding the Maven dependency also makes the functions directly available to jq. This behavior is deprecated and will be removed at some point in the future.
515+
504516
<details>
505517
<summary>List of Functions</summary>
506518

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.20210926</version>
11+
<version>1.0.0-preview.20210928</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.20210926</version>
18+
<version>1.0.0-preview.20210928</version>
1919
</dependency>
2020
<dependency>
2121
<groupId>commons-cli</groupId>

jackson-jq-cli/src/main/java/net/thisptr/jackson/jq/cli/Main.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.IOException;
66
import java.io.InputStream;
77
import java.io.InputStreamReader;
8+
import java.nio.file.FileSystems;
89
import java.util.Arrays;
910
import java.util.List;
1011

@@ -28,6 +29,10 @@
2829
import net.thisptr.jackson.jq.Versions;
2930
import net.thisptr.jackson.jq.exception.JsonQueryException;
3031
import net.thisptr.jackson.jq.internal.functions.EnvFunction;
32+
import net.thisptr.jackson.jq.module.ModuleLoader;
33+
import net.thisptr.jackson.jq.module.loaders.BuiltinModuleLoader;
34+
import net.thisptr.jackson.jq.module.loaders.ChainedModuleLoader;
35+
import net.thisptr.jackson.jq.module.loaders.FileSystemModuleLoader;
3136

3237
public class Main {
3338
private static final ObjectMapper MAPPER = new ObjectMapper();
@@ -108,6 +113,11 @@ public static void main(String[] args) throws IOException, ParseException {
108113
BuiltinFunctionLoader.getInstance().loadFunctions(version, scope);
109114
scope.addFunction("env", 0, new EnvFunction());
110115

116+
scope.setModuleLoader(new ChainedModuleLoader(new ModuleLoader[] {
117+
BuiltinModuleLoader.getInstance(),
118+
new FileSystemModuleLoader(scope, version, FileSystems.getDefault().getPath("").toAbsolutePath()),
119+
}));
120+
111121
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
112122
final JsonParser parser = MAPPER.getFactory().createParser(reader);
113123
while (!parser.isClosed()) {

jackson-jq-extra/pom.xml

Lines changed: 3 additions & 3 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.20210926</version>
11+
<version>1.0.0-preview.20210928</version>
1212
</parent>
1313

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

@@ -26,7 +26,7 @@
2626
<artifactId>maven-bundle-plugin</artifactId>
2727
<configuration>
2828
<instructions>
29-
<Include-Resource>META-INF/services/net.thisptr.jackson.jq.Function=${project.build.outputDirectory}/META-INF/services/net.thisptr.jackson.jq.Function</Include-Resource>
29+
<Include-Resource>META-INF/services/net.thisptr.jackson.jq.Function=${project.build.outputDirectory}/META-INF/services/net.thisptr.jackson.jq.Function,META-INF/services/net.thisptr.jackson.jq.module.Module=${project.build.outputDirectory}/META-INF/services/net.thisptr.jackson.jq.module.Module</Include-Resource>
3030
</instructions>
3131
</configuration>
3232
</plugin>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package net.thisptr.jackson.jq.extra;
2+
3+
import com.google.auto.service.AutoService;
4+
5+
import net.thisptr.jackson.jq.BuiltinFunction;
6+
import net.thisptr.jackson.jq.Function;
7+
import net.thisptr.jackson.jq.extra.functions.HostnameFunction;
8+
import net.thisptr.jackson.jq.extra.functions.RandomFunction;
9+
import net.thisptr.jackson.jq.extra.functions.StrFTimeFunction;
10+
import net.thisptr.jackson.jq.extra.functions.StrPTimeFunction;
11+
import net.thisptr.jackson.jq.extra.functions.TimestampFunction;
12+
import net.thisptr.jackson.jq.extra.functions.UriDecodeFunction;
13+
import net.thisptr.jackson.jq.extra.functions.UriParseFunction;
14+
import net.thisptr.jackson.jq.extra.functions.Uuid4Function;
15+
import net.thisptr.jackson.jq.module.BuiltinModule;
16+
import net.thisptr.jackson.jq.module.Module;
17+
import net.thisptr.jackson.jq.module.SimpleModule;
18+
19+
@AutoService(Module.class)
20+
@BuiltinModule(path = "jackson-jq/extras")
21+
public class ModuleImpl extends SimpleModule {
22+
23+
public ModuleImpl() {
24+
addFunction(new HostnameFunction());
25+
addFunction(new RandomFunction());
26+
addFunction(new StrFTimeFunction());
27+
addFunction(new StrPTimeFunction());
28+
addFunction(new TimestampFunction());
29+
addFunction(new UriDecodeFunction());
30+
addFunction(new UriParseFunction());
31+
addFunction(new Uuid4Function());
32+
}
33+
34+
private void addFunction(final Function f) {
35+
final BuiltinFunction annotation = f.getClass().getAnnotation(BuiltinFunction.class);
36+
for (final String fname : annotation.value())
37+
addFunction(fname, f);
38+
}
39+
}

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.20210926</version>
11+
<version>1.0.0-preview.20210928</version>
1212
</parent>
1313

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

0 commit comments

Comments
 (0)