Skip to content

Commit 9bbcd7a

Browse files
authored
Merge pull request #22 from dai0304/feature/tweak-logging-json-patches
Tweak logging
2 parents 106a19c + 16cd510 commit 9bbcd7a

File tree

1 file changed

+5
-1
lines changed
  • spar-wings-json-patch/src/main/java/jp/xet/sparwings/jackson/patch

1 file changed

+5
-1
lines changed

spar-wings-json-patch/src/main/java/jp/xet/sparwings/jackson/patch/JsonPatches.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import lombok.RequiredArgsConstructor;
2121
import lombok.ToString;
2222

23+
import com.fasterxml.jackson.core.JsonParseException;
2324
import com.fasterxml.jackson.databind.JsonNode;
2425
import com.fasterxml.jackson.databind.ObjectMapper;
2526
import com.github.fge.jsonpatch.JsonPatch;
@@ -38,13 +39,16 @@ class JsonPatches<T> implements UpdateRequest<T> {
3839
@Override
3940
@SuppressWarnings("unchecked")
4041
public T apply(T original) throws IllegalPatchException {
42+
String json = null;
4143
try {
4244
JsonPatch patch = JsonPatch.fromJson(node);
43-
String json = mapper.writeValueAsString(original);
45+
json = mapper.writeValueAsString(original);
4446
JsonNode originalNode = mapper.readTree(json);
4547
JsonNode patchedNode = patch.apply(originalNode);
4648
T patched = mapper.treeToValue(patchedNode, (Class<T>) original.getClass());
4749
return patched; // NOPMD
50+
} catch (JsonParseException e) {
51+
throw new IllegalStateException("Failed to parse original JSON:" + json, e);
4852
} catch (IllegalArgumentException | JsonPatchException | IOException | NullPointerException e) { // NOPMD
4953
throw new IllegalPatchException(e);
5054
}

0 commit comments

Comments
 (0)