File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed
spar-wings-json-patch/src/main/java/jp/xet/sparwings/jackson/patch Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change 2020import lombok .RequiredArgsConstructor ;
2121import lombok .ToString ;
2222
23+ import com .fasterxml .jackson .core .JsonParseException ;
2324import com .fasterxml .jackson .databind .JsonNode ;
2425import com .fasterxml .jackson .databind .ObjectMapper ;
2526import 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 }
You can’t perform that action at this time.
0 commit comments