Skip to content

Commit 28417c2

Browse files
author
Piotr Bugara
committed
Merge branch 'master' into feature/37_test_with_null_agains_empty_path
# Conflicts: # src/main/java/com/gravity9/jsonpatch/RemoveOperation.java
2 parents ee0e371 + 41984a2 commit 28417c2

19 files changed

+149
-92
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[![License LGPLv3][LGPLv3 badge]][LGPLv3]
22
[![License ASL 2.0][ASL 2.0 badge]][ASL 2.0]
3+
[![Pipeline][GitHub Acitons badge]][GitHub Acitons link]
34
[![Maven Central][Maven Central badge]][Maven]
45

56
## Read me first
@@ -12,8 +13,9 @@ only.
1213

1314
## Fork
1415

15-
This library was forked from the original repository(https://github.com/java-json-tools/json-patch) by gravity9 to
16-
maintain and extend it as the original library is no longer supported.
16+
This library was forked by [gravity9](https://www.gravity9.com) from the
17+
original [repository](https://github.com/java-json-tools/json-patch)
18+
to maintain and extend it as the original library is no longer supported.
1719

1820
## What this is
1921

@@ -598,8 +600,17 @@ Examples of JsonPath:
598600
* `$..book[(@.length-1)].title` - not supported. Use `$..book[-1:].title` instead.
599601

600602
[LGPLv3 badge]: https://img.shields.io/:license-LGPLv3-blue.svg
603+
601604
[LGPLv3]: http://www.gnu.org/licenses/lgpl-3.0.html
605+
602606
[ASL 2.0 badge]: https://img.shields.io/:license-Apache%202.0-blue.svg
607+
603608
[ASL 2.0]: http://www.apache.org/licenses/LICENSE-2.0.html
609+
610+
[GitHub Acitons badge]: https://github.com/gravity9-tech/json-patch-path/actions/workflows/push-workflow.yaml/badge.svg?branch=master
611+
612+
[GitHub Acitons link]: https://github.com/gravity9-tech/json-patch-path/actions/workflows/push-workflow.yaml
613+
604614
[Maven Central badge]: https://img.shields.io/maven-central/v/com.github.java-json-tools/json-patch.svg
615+
605616
[Maven]: https://search.maven.org/artifact/com.github.java-json-tools/json-patch

RELEASE-NOTES.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## 2.0.0
2+
3+
The project has been taken over by [gravity9](https://www.gravity9.com).
4+
5+
* Changed groupId and artifactId
6+
* The library now uses Java 11 as base
7+
* Added support for JSON Path
8+
* Added support for ignoring fields in JSON diff
9+
* Added support for defining a custom ObjectMapper for JsonMergePatch
10+
* Added more context to JsonPatchException thrown in all operations
11+
* Added more test cases and examples
12+
* Upgraded versions of most libraries and tools used in the project
13+
* Fixed outstanding CVE vulnerabilities where possible
14+
* Multiple bugfixes
15+
116
## 1.10
217

318
* First release at java-json-tools.
@@ -6,7 +21,7 @@
621
## 1.9
722

823
* Completely new JSON diff implementation; less smart than the previous one but
9-
bug free
24+
bug free
1025
* Depend on AssertJ.
1126

1227
## 1.8

src/main/java/com/gravity9/jsonpatch/AddOperation.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,15 @@ public JsonNode applyInternal(final JsonNode node) throws JsonPatchException {
8282

8383
final DocumentContext nodeContext = JsonPath.parse(node.deepCopy());
8484
final JsonNode evaluatedJsonParents = nodeContext.read(pathToParent);
85-
if (evaluatedJsonParents == null) {
86-
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.noSuchParent"));
87-
}
8885
if (!evaluatedJsonParents.isContainerNode()) {
89-
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.parentNotContainer"));
86+
throw JsonPatchException.parentNotContainer(pathToParent);
9087
}
9188

9289
if (pathDetails.doesContainFiltersOrMultiIndexesNotation()) { // json filter result is always a list
9390
for (int i = 0; i < evaluatedJsonParents.size(); i++) {
9491
JsonNode parentNode = evaluatedJsonParents.get(i);
9592
if (!parentNode.isContainerNode()) {
96-
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.parentNotContainer"));
93+
throw JsonPatchException.parentNotContainer(pathToParent + " at index " + i);
9794
}
9895
DocumentContext containerContext = JsonPath.parse(parentNode);
9996
if (parentNode.isArray()) {
@@ -133,11 +130,13 @@ private int verifyAndGetArrayIndex(String stringIndex, int size) throws JsonPatc
133130
try {
134131
index = Integer.parseInt(stringIndex);
135132
} catch (NumberFormatException ignored) {
136-
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.notAnIndex"));
133+
throw JsonPatchException.notAnIndex(stringIndex);
137134
}
135+
138136
if (index < 0 || index > size) {
139-
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.noSuchIndex"));
137+
throw JsonPatchException.noSuchIndex(index);
140138
}
139+
141140
return index;
142141
}
143142
}

src/main/java/com/gravity9/jsonpatch/CopyOperation.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ public CopyOperation(@JsonProperty("from") final String from, @JsonProperty("pat
5151
public JsonNode applyInternal(final JsonNode node) throws JsonPatchException {
5252
final String jsonPath = JsonPathParser.parsePathToJsonPath(from);
5353
final JsonNode dupData = JsonPath.parse(node.deepCopy()).read(jsonPath);
54-
if (dupData == null) {
55-
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.noSuchPath"));
56-
}
5754
return new AddOperation(path, dupData).apply(node);
5855
}
5956
}

src/main/java/com/gravity9/jsonpatch/JsonPatchException.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package com.gravity9.jsonpatch;
2121

22+
import static com.gravity9.jsonpatch.JsonPatchOperation.BUNDLE;
23+
2224
public final class JsonPatchException extends Exception {
2325

2426
public JsonPatchException(final String message) {
@@ -28,4 +30,21 @@ public JsonPatchException(final String message) {
2830
public JsonPatchException(final String message, final Throwable cause) {
2931
super(message, cause);
3032
}
33+
34+
public static JsonPatchException valueTestFailure(Object expected, Object found) {
35+
return new JsonPatchException(BUNDLE.getMessage("jsonPatch.valueTestFailure") +
36+
": expected '" + expected + "' but found '" + found + "'");
37+
}
38+
39+
public static JsonPatchException notAnIndex(String index) {
40+
return new JsonPatchException(BUNDLE.getMessage("jsonPatch.notAnIndex") + ": " + index);
41+
}
42+
43+
public static JsonPatchException noSuchIndex(Integer index) {
44+
return new JsonPatchException(BUNDLE.getMessage("jsonPatch.noSuchIndex") + ": " + index);
45+
}
46+
47+
public static JsonPatchException parentNotContainer(String path) {
48+
return new JsonPatchException(BUNDLE.getMessage("jsonPatch.parentNotContainer") + ": " + path);
49+
}
3150
}

src/main/java/com/gravity9/jsonpatch/JsonPatchMessages.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public final class JsonPatchMessages implements MessageBundleLoader {
2727

2828
@Override
2929
public MessageBundle getBundle() {
30-
return PropertiesBundle.forPath("/com/github/fge/jsonpatch/messages");
30+
return PropertiesBundle.forPath("/com/gravity9/jsonpatch/messages");
3131
}
3232
}

src/main/java/com/gravity9/jsonpatch/MoveOperation.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ public JsonNode applyInternal(final JsonNode node) throws JsonPatchException {
7575
}
7676
String jsonPath = JsonPathParser.parsePathToJsonPath(from);
7777
final JsonNode movedNode = JsonPath.parse(node.deepCopy()).read(jsonPath, JsonNode.class);
78-
if (movedNode == null) {
79-
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.noSuchPath"));
80-
}
8178
final JsonPatchOperation remove = new RemoveOperation(from);
8279
final JsonPatchOperation add = new AddOperation(path, movedNode);
8380
return add.apply(remove.apply(node));

src/main/java/com/gravity9/jsonpatch/RemoveOperation.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ public JsonNode applyInternal(final JsonNode node) throws JsonPatchException {
5252

5353
final DocumentContext nodeContext = JsonPath.parse(node.deepCopy());
5454
final String jsonPath = JsonPathParser.parsePathToJsonPath(path);
55-
56-
if (nodeContext.read(jsonPath) == null) {
57-
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.noSuchPath"));
58-
}
5955
return nodeContext
6056
.delete(jsonPath)
6157
.read("$", JsonNode.class);

src/main/java/com/gravity9/jsonpatch/ReplaceOperation.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ public ReplaceOperation(@JsonProperty("path") final String path, @JsonProperty("
4545
public JsonNode applyInternal(final JsonNode node) throws JsonPatchException {
4646
final String jsonPath = JsonPathParser.parsePathToJsonPath(path);
4747
final DocumentContext nodeContext = JsonPath.parse(node.deepCopy());
48-
final JsonNode nodeAtPath = nodeContext.read(jsonPath);
49-
if (nodeAtPath == null) {
50-
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.noSuchPath"));
51-
}
5248
final JsonNode replacement = value.deepCopy();
5349
if (path.isEmpty()) {
5450
return replacement;

src/main/java/com/gravity9/jsonpatch/TestOperation.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,8 @@ public TestOperation(@JsonProperty("path") final String path, @JsonProperty("val
5151
public JsonNode applyInternal(final JsonNode node) throws JsonPatchException {
5252
final String jsonPath = JsonPathParser.parsePathToJsonPath(path);
5353
final JsonNode tested = JsonPath.parse(node.deepCopy()).read(jsonPath);
54-
if (tested == null) {
55-
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.noSuchPath"));
56-
}
5754
if (!EQUIVALENCE.equivalent(tested, value)) {
58-
throw new JsonPatchException(BUNDLE.getMessage("jsonPatch.valueTestFailure"));
55+
throw JsonPatchException.valueTestFailure(value, tested);
5956
}
6057
return node.deepCopy();
6158
}

0 commit comments

Comments
 (0)