Skip to content

Commit

Permalink
Merge pull request #83 from Shawyeok/hotfix/inconsistent-keys-order
Browse files Browse the repository at this point in the history
Fix output fields order inconsistent with the input (#81)
  • Loading branch information
eiiches authored Aug 7, 2021
2 parents 5837272 + 92ffcca commit afaa37e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.thisptr.jackson.jq.internal.tree;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -26,7 +26,7 @@ public void add(final FieldConstruction field) {

@Override
public void apply(final Scope scope, final JsonNode in, final Path ipath, final PathOutput output, final boolean requirePath) throws JsonQueryException {
final Map<String, JsonNode> tmp = new HashMap<>();
final Map<String, JsonNode> tmp = new LinkedHashMap<>(fields.size());
applyRecursive(scope, in, output, fields, tmp);
}

Expand Down
16 changes: 15 additions & 1 deletion jackson-jq/src/test/resources/jq-test-extra-ok.json
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@
"q": ".num_entries[\"1\"] = 10",
"in": {"num_entries": {"2": 20}},
"out": [
{"num_entries": {"1": 10, "2": 20}}
{"num_entries": {"2": 20, "1": 10}}
]
},
{
Expand Down Expand Up @@ -1036,5 +1036,19 @@
[20, 30],
[20, 40]
]
},
{
"q": "{a: {depth: 1, b: {depth: 2}}}",
"in": null,
"out": [
{
"a": {
"depth": 1,
"b": {
"depth": 2
}
}
}
]
}
]
2 changes: 1 addition & 1 deletion jackson-jq/src/test/resources/tests/jq-1.5.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@
- q: '.foo = .bar'
in: {"bar": 42}
out:
- {"foo": 42, "bar": 42}
- {"bar": 42, "foo": 42}
v: '[1.5, 1.5]'
- q: '.foo |= .+1'
in: {"foo": 42}
Expand Down
2 changes: 1 addition & 1 deletion jackson-jq/src/test/resources/tests/jq-1.6.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@
- q: '.foo = .bar'
in: {"bar": 42}
out:
- {"foo": 42, "bar": 42}
- {"bar": 42, "foo": 42}
v: '[1.6, 1.6]'
- q: '.foo |= .+1'
in: {"foo": 42}
Expand Down

0 comments on commit afaa37e

Please sign in to comment.