FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Informative msgs when JsonPatchException is thrown by objectsmiths · Pull Request #103 · java-json-tools/json-patch · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .gradle  (1) .java  (7) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 2 additions & 2 deletions build.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ buildscript {
repositories {
mavenCentral()
maven {
url "http://repo.springsource.org/plugins-release";
url "https://repo.springsource.org/plugins-release";
}
}
dependencies {
Expand All @@ -31,7 +31,7 @@ buildscript {
};

plugins {
id("net.ltgt.errorprone") version "0.8.1" apply false
id("net.ltgt.errorprone") version "1.3.0" apply false
}

configure(allprojects) {
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/com/github/fge/jsonpatch/AddOperation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,20 @@ public JsonNode apply(final JsonNode node)
*/
final JsonNode parentNode = path.parent().path(node);
if (parentNode.isMissingNode())
throw new JsonPatchException(BUNDLE.getMessage(
"jsonPatch.noSuchParent"));
if (!parentNode.isContainerNode())
throw new JsonPatchException(BUNDLE.getMessage(
"jsonPatch.parentNotContainer"));
{
String msg = BUNDLE.getMessage("jsonPatch.noSuchParent");
if(node!=null) {
msg = node.toString() + " " + msg;
}
throw new JsonPatchException(msg);
}
if (!parentNode.isContainerNode()) {
String msg = BUNDLE.getMessage("jsonPatch.parentNotContainer");
if(node!=null) {
msg = node.toString() + " " + msg;
}
throw new JsonPatchException(msg);
}
return parentNode.isArray()
? addToArray(path, node)
: addToObject(path, node);
Expand All @@ -119,12 +128,12 @@ private JsonNode addToArray(final JsonPointer path, final JsonNode node)
try {
index = Integer.parseInt(token.toString());
} catch (NumberFormatException ignored) {
throw new JsonPatchException(BUNDLE.getMessage(
throw new JsonPatchException("[] " + BUNDLE.getMessage(
"jsonPatch.notAnIndex"));
}

if (index < 0 || index > size)
throw new JsonPatchException(BUNDLE.getMessage(
throw new JsonPatchException(node.toString() + " " + BUNDLE.getMessage(
"jsonPatch.noSuchIndex"));

target.insert(index, value);
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ public JsonNode apply(final JsonNode node)
throws JsonPatchException
{
final JsonNode dupData = from.path(node).deepCopy();
if (dupData.isMissingNode())
throw new JsonPatchException(BUNDLE.getMessage(
"jsonPatch.noSuchPath"));
if(dupData.isMissingNode()){
String msg = BUNDLE.getMessage("jsonPatch.noSuchPath");
if(dupData!=null) {
msg = node.toString() + " " + msg;
}
throw new JsonPatchException(msg);
}
return new AddOperation(path, dupData).apply(node);
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,33 @@ public JsonNode apply(final JsonNode node)
if (from.equals(path))
return node.deepCopy();
final JsonNode movedNode = from.path(node);
if (movedNode.isMissingNode())
throw new JsonPatchException(BUNDLE.getMessage(
"jsonPatch.noSuchPath"));
if (movedNode.isMissingNode()) {
String msg = BUNDLE.getMessage("jsonPatch.noSuchPath");
if(node!=null) {
msg = node.toString() + " " + msg;
}
throw new JsonPatchException(msg);
}
final JsonPatchOperation remove = new RemoveOperation(from);
final JsonPatchOperation add = new AddOperation(path, movedNode);
return add.apply(remove.apply(node));
JsonNode returnNode = null;
try {
returnNode = add.apply(remove.apply(node));
}
catch(JsonPatchException jpe)
{
String msg = BUNDLE.getMessage("jsonPatch.noSuchParent");
if(jpe.getMessage().contains(msg))
{
// Rethrow the JsonPatchException with a new message
msg = node.toString() + " " + msg;
throw new JsonPatchException(msg);
}
else
{
throw jpe;
}
}
return returnNode;
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ public JsonNode apply(final JsonNode node)
if (path.isEmpty())
return MissingNode.getInstance();
if (path.path(node).isMissingNode())
throw new JsonPatchException(BUNDLE.getMessage(
"jsonPatch.noSuchPath"));
{
String msg = BUNDLE.getMessage("jsonPatch.noSuchPath");
if(node!=null) {
msg = node.toString() + " " + msg;
}
throw new JsonPatchException(msg);
}
final JsonNode ret = node.deepCopy();
final JsonNode parentNode = path.parent().get(ret);
final String raw = Iterables.getLast(path).getToken().getRaw();
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ public JsonNode apply(final JsonNode node)
* If remove is done first, the array is empty and add rightly complains
* that there is no such index in the array.
*/
if (path.path(node).isMissingNode())
throw new JsonPatchException(BUNDLE.getMessage(
"jsonPatch.noSuchPath"));
if (path.path(node).isMissingNode()) {
String msg = BUNDLE.getMessage("jsonPatch.noSuchPath");
if(node!=null) {
msg = node.toString() + " " + msg;
}
throw new JsonPatchException(msg);
}
final JsonNode replacement = value.deepCopy();
if (path.isEmpty())
return replacement;
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ public JsonNode apply(final JsonNode node)
throws JsonPatchException
{
final JsonNode tested = path.path(node);
if (tested.isMissingNode())
throw new JsonPatchException(BUNDLE.getMessage(
"jsonPatch.noSuchPath"));
if (tested.isMissingNode()) {
String msg = BUNDLE.getMessage("jsonPatch.noSuchPath");
if(node!=null) {
msg = node.toString() + " " + msg;
}
throw new JsonPatchException(msg);
}
if (!EQUIVALENCE.equivalent(tested, value))
throw new JsonPatchException(BUNDLE.getMessage(
throw new JsonPatchException(node.toString() + " " + BUNDLE.getMessage(
"jsonPatch.valueTestFailure"));
return node.deepCopy();
}
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ public final void errorsAreCorrectlyReported(final JsonNode patch,
throws IOException
{
final JsonPatchOperation op = reader.readValue(patch);

try {
op.apply(node);
fail("No exception thrown!!");
} catch (JsonPatchException e) {
assertEquals(e.getMessage(), message);
String msg = message;
if(node!=null) {
msg = node.toString() + " " + msg;
}
assertEquals(e.getMessage(), msg);
}
}

Expand Down

Back | FazBrowse Home | New Git URL