Skip to content

Commit c2d4c87

Browse files
Merge branch 'release/1.2.0' into master/1.x
2 parents c03af86 + 8419a88 commit c2d4c87

File tree

15 files changed

+164
-40
lines changed

15 files changed

+164
-40
lines changed

.github/workflows/deploy-snapshot.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ jobs:
88
build:
99
runs-on: ubuntu-22.04
1010
steps:
11-
- uses: actions/[email protected].1
11+
- uses: actions/[email protected].2
1212
- name: Set up JDK 1.8
13-
uses: actions/setup-java@v4.4.0
13+
uses: actions/setup-java@v4.5.0
1414
with:
1515
java-version: '8'
1616
distribution: 'temurin'

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ jobs:
1313
build:
1414
runs-on: ubuntu-22.04
1515
steps:
16-
- uses: actions/[email protected].1
16+
- uses: actions/[email protected].2
1717
with:
1818
fetch-depth: 0
1919

2020
- name: Set up JDK 1.8
21-
uses: actions/setup-java@v4.4.0
21+
uses: actions/setup-java@v4.5.0
2222
with:
2323
java-version: '8'
2424
distribution: 'temurin'

.github/workflows/test-pull-requests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ jobs:
77
build:
88
runs-on: ubuntu-22.04
99
steps:
10-
- uses: actions/[email protected].1
10+
- uses: actions/[email protected].2
1111
- name: Set up JDK 1.8
12-
uses: actions/setup-java@v4.4.0
12+
uses: actions/setup-java@v4.5.0
1313
with:
1414
java-version: '8'
1515
distribution: 'temurin'

README.md

Lines changed: 22 additions & 22 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.1.0/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.2.0/jar) on search.maven.org.
1616

1717
```xml
1818
<dependency>
1919
<groupId>net.thisptr</groupId>
2020
<artifactId>jackson-jq</artifactId>
21-
<version>1.1.0</version>
21+
<version>1.2.0</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.1.0/jackson-jq-cli-1.1.0.jar
35+
$ curl -LO https://repo1.maven.org/maven2/net/thisptr/jackson-jq-cli/1.2.0/jackson-jq-cli-1.2.0.jar
3636

37-
$ java -jar jackson-jq-cli-1.1.0.jar --help
37+
$ java -jar jackson-jq-cli-1.2.0.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.1.0.jar '.foo'
45+
$ java -jar jackson-jq-cli-1.2.0.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.1.0.jar --jq 1.5 'join("-")'
53+
$ java -jar jackson-jq-cli-1.2.0.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.1.0.jar --jq 1.6 'join("-")' # jq-1.6 can join any values, not only strings
57+
$ java -jar jackson-jq-cli-1.2.0.jar --jq 1.6 'join("-")' # jq-1.6 can join any values, not only strings
5858
["1", 2]
5959
"1-2"
6060
```
@@ -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.1.0.jar -n '1 + 3 | (. * 2)' # interpreted as (1 + 3) | (. * 2)
239+
$ java -jar jackson-jq-cli-1.2.0.jar -n '1 + 3 | (. * 2)' # interpreted as (1 + 3) | (. * 2)
240240
8
241-
$ java -jar jackson-jq-cli-1.1.0.jar -n '1 + 3 as $a | ($a * 2)' # interpreted as (1 + 3) as $a | ($a * 2)
241+
$ java -jar jackson-jq-cli-1.2.0.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.1.0.jar -n '1 + 3 as $a | ($a * 2)' # interpreted a
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.1.0.jar -n '1 + 3 as $a | ($a * 2)' # interpreted as (1 + 3) as $a | ($a * 2)
250+
$ java -jar jackson-jq-cli-1.2.0.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.1.0.jar -n 'def f: 1; def g: f; def f: 2; g'
277+
$ java -jar jackson-jq-cli-1.2.0.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.1.0.jar -n 'def f: 1; def g: f; def f: 2; g'
283283
Avoid using the duplicate function name.
284284

285285
```console
286-
$ java -jar jackson-jq-cli-1.1.0.jar -n 'def f1: 1; def g: f1; def f2: 2; g'
286+
$ java -jar jackson-jq-cli-1.2.0.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.1.0.jar -n '0 / 0'
356+
$ java -jar jackson-jq-cli-1.2.0.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.1.0.jar --jq 1.6 -n '[1,2,3] | ((.[] | select(. > 1)) |= empty)'
389+
$ java -jar jackson-jq-cli-1.2.0.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.1.0.jar --jq 1.5 -n '[1,2,3] | ((.[] | select(. > 1)) |= empty)'
391+
$ java -jar jackson-jq-cli-1.2.0.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.1.0.jar --jq 1.6 -n '[1,2,3] | _modify((.[] | select(. > 1)); empty)'
400+
$ java -jar jackson-jq-cli-1.2.0.jar --jq 1.6 -n '[1,2,3] | _modify((.[] | select(. > 1)); empty)'
401401
[ 1, 3 ]
402-
$ java -jar jackson-jq-cli-1.1.0.jar --jq 1.5 -n '[1,2,3] | _modify((.[] | select(. > 1)); empty)'
402+
$ java -jar jackson-jq-cli-1.2.0.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.1.0.jar --jq 1.5 -c 'path(.foo as $a | $a)' <<< '{"foo": 1}'
422+
$ java -jar jackson-jq-cli-1.2.0.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.1.0.jar --jq 1.6 -c 'path(.foo as $a | $a)' <<< '{"foo": 1}'
431+
$ java -jar jackson-jq-cli-1.2.0.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.1.0.jar -n 'label $a | label $b | try (break $b) catch .'
455+
$ java -jar jackson-jq-cli-1.2.0.jar -n 'label $a | label $b | try (break $b) catch .'
456456
{
457457
"__jq" : 0
458458
}
@@ -482,7 +482,7 @@ $ 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.1.0.jar -n '"x" | indices("")'
485+
$ java -jar jackson-jq-cli-1.2.0.jar -n '"x" | indices("")'
486486
[ ]
487487
```
488488

@@ -499,7 +499,7 @@ To use this module, you need to add the following Maven dependency and set `Buil
499499
<dependency>
500500
<groupId>net.thisptr</groupId>
501501
<artifactId>jackson-jq-extra</artifactId>
502-
<version>1.1.0</version>
502+
<version>1.2.0</version>
503503
</dependency>
504504
```
505505

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.1.0</version>
11+
<version>1.2.0</version>
1212
</parent>
1313

1414
<dependencies>
1515
<dependency>
1616
<groupId>net.thisptr</groupId>
1717
<artifactId>jackson-jq-extra</artifactId>
18-
<version>1.1.0</version>
18+
<version>1.2.0</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.1.0</version>
11+
<version>1.2.0</version>
1212
</parent>
1313

1414
<dependencies>
1515
<dependency>
1616
<groupId>net.thisptr</groupId>
1717
<artifactId>jackson-jq</artifactId>
18-
<version>1.1.0</version>
18+
<version>1.2.0</version>
1919
</dependency>
2020
</dependencies>
2121

jackson-jq/pom.xml

Lines changed: 1 addition & 1 deletion
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.1.0</version>
11+
<version>1.2.0</version>
1212
</parent>
1313

1414
<dependencies>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package net.thisptr.jackson.jq.internal.functions;
2+
3+
import com.fasterxml.jackson.databind.JsonNode;
4+
import com.fasterxml.jackson.databind.node.JsonNodeType;
5+
import com.google.auto.service.AutoService;
6+
import net.thisptr.jackson.jq.*;
7+
import net.thisptr.jackson.jq.exception.JsonQueryException;
8+
import net.thisptr.jackson.jq.internal.misc.Preconditions;
9+
import net.thisptr.jackson.jq.internal.misc.JsonNodeUtils;
10+
import net.thisptr.jackson.jq.path.Path;
11+
12+
import java.time.Instant;
13+
import java.time.format.DateTimeParseException;
14+
import java.util.List;
15+
16+
@AutoService(Function.class)
17+
@BuiltinFunction({ "fromdateiso8601/0" })
18+
public class FromDateIso8601Function implements Function {
19+
@Override
20+
public void apply(final Scope scope, final List<Expression> args, final JsonNode in, final Path ipath, final PathOutput output, final Version version) throws JsonQueryException {
21+
Preconditions.checkInputType("fromdateiso8601", in, JsonNodeType.STRING);
22+
try {
23+
String iso8601String = in.asText();
24+
// In future versions of JQ, it may need to be revisited due to fractional support: https://github.com/jqlang/jq/issues/1409
25+
if (iso8601String.length() > 20) {
26+
throw new JsonQueryException(String.format("date \"%s\" does not match format \"%%Y-%%m-%%dT%%H:%%M:%%SZ\"", iso8601String));
27+
}
28+
long epochSeconds = Instant.parse(iso8601String).getEpochSecond();
29+
output.emit(JsonNodeUtils.asNumericNode(epochSeconds), null);
30+
} catch (DateTimeParseException e) {
31+
throw new JsonQueryException(e);
32+
}
33+
}
34+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package net.thisptr.jackson.jq.internal.functions;
2+
3+
import com.fasterxml.jackson.databind.JsonNode;
4+
import com.fasterxml.jackson.databind.node.JsonNodeType;
5+
import com.fasterxml.jackson.databind.node.TextNode;
6+
import com.google.auto.service.AutoService;
7+
import net.thisptr.jackson.jq.*;
8+
import net.thisptr.jackson.jq.exception.JsonQueryException;
9+
import net.thisptr.jackson.jq.internal.misc.Preconditions;
10+
import net.thisptr.jackson.jq.path.Path;
11+
12+
import java.time.DateTimeException;
13+
import java.time.Instant;
14+
import java.util.List;
15+
16+
@AutoService(Function.class)
17+
@BuiltinFunction({ "todateiso8601/0" })
18+
public class ToDateIso8601Function implements Function {
19+
@Override
20+
public void apply(final Scope scope, final List<Expression> args, final JsonNode in, final Path ipath, final PathOutput output, final Version version) throws JsonQueryException {
21+
Preconditions.checkInputType("todateiso8601", in, JsonNodeType.NUMBER);
22+
try {
23+
long epochSeconds = in.asLong();
24+
String iso8601String = Instant.ofEpochSecond(epochSeconds).toString();
25+
output.emit(new TextNode(iso8601String), null);
26+
} catch (DateTimeException e) {
27+
throw new JsonQueryException(e);
28+
}
29+
}
30+
}

jackson-jq/src/main/java/net/thisptr/jackson/jq/internal/tree/binaryop/assignment/ComplexAssignment.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.List;
55

66
import com.fasterxml.jackson.databind.JsonNode;
7+
import com.fasterxml.jackson.databind.node.NullNode;
78

89
import net.thisptr.jackson.jq.Expression;
910
import net.thisptr.jackson.jq.PathOutput;
@@ -38,7 +39,7 @@ public void apply(final Scope scope, final JsonNode in, final Path ipath, final
3839
}, true);
3940
JsonNode out = in;
4041
for (final Path lpath : lpaths)
41-
out = lpath.mutate(out, (lval) -> operator.apply(scope.getObjectMapper(), lval, rval));
42+
out = lpath.mutate(out, (lval) -> operator.apply(scope.getObjectMapper(), lval == null ? NullNode.getInstance() : lval, rval));
4243
output.emit(out, null);
4344
});
4445
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package net.thisptr.jackson.jq.internal;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.io.IOException;
6+
import java.util.ArrayList;
7+
import java.util.Arrays;
8+
import java.util.List;
9+
10+
import javax.management.ObjectName;
11+
12+
import org.junit.jupiter.api.Test;
13+
14+
import com.fasterxml.jackson.databind.JsonNode;
15+
import com.fasterxml.jackson.databind.ObjectMapper;
16+
import com.fasterxml.jackson.databind.node.IntNode;
17+
import com.fasterxml.jackson.databind.node.NullNode;
18+
import com.fasterxml.jackson.databind.node.ObjectNode;
19+
20+
import net.thisptr.jackson.jq.BuiltinFunctionLoader;
21+
import net.thisptr.jackson.jq.JsonQuery;
22+
import net.thisptr.jackson.jq.Scope;
23+
import net.thisptr.jackson.jq.Versions;
24+
import net.thisptr.jackson.jq.exception.JsonQueryException;
25+
import net.thisptr.jackson.jq.internal.javacc.ExpressionParser;
26+
27+
public class NullLHSFunctionTest {
28+
@Test
29+
public void test() throws IOException {
30+
final ObjectMapper mapper = new ObjectMapper();
31+
final Scope scope = Scope.newEmptyScope();
32+
BuiltinFunctionLoader.getInstance().loadFunctions(Versions.JQ_1_5, scope);
33+
ObjectNode input = mapper.createObjectNode().set("input", mapper.createArrayNode().add(1));
34+
assertEquals(Arrays.asList(input.deepCopy().set("output", mapper.createArrayNode().add(2))), JsonQueryFunctionTest.eval(scope, ".output+=[.input[0]+1]", input));
35+
}
36+
}

jackson-jq/src/test/resources/tests/constructs/assignments.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,13 @@
109109
v: "(,1.5]"
110110
failing: true
111111
justification: "The jq documentation explicitly states `$var.foo is not a valid or useful path expression in .`."
112+
113+
- q: '.foo += null'
114+
in: {}
115+
out:
116+
- {foo: null}
117+
118+
- q: '.foo += 1'
119+
in: {}
120+
out:
121+
- {foo: 1}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- q: 'fromdateiso8601'
2+
in: "2023-09-30T00:00:00Z"
3+
out:
4+
- 1696032000
5+
6+
- q: 'try fromdateiso8601 catch .'
7+
in: "2023-09-30T00:00:00.000Z"
8+
out:
9+
- "date \"2023-09-30T00:00:00.000Z\" does not match format \"%Y-%m-%dT%H:%M:%SZ\""

0 commit comments

Comments
 (0)