@Test public void createRoad() throws Exception { JsonNode road = mapper.readTree("{\"name\":\"road1\"}"); List<PatchOperation> operations = singletonList(PatchOperation.add("", road)); JsonNode result = underTest.apply(NullNode.getInstance(), operations); assertThat(result.isMissingNode(), is(false)); assertThat(result.path("name").textValue(), is("road1")); }
public JsonNode apply(JsonNode document, List<PatchOperation> patchOperations) throws PatchApplicationException { try { JsonNode patch = mapper.convertValue(patchOperations, JsonNode.class); JsonPatch jsonPatch = JsonPatch.fromJson(patch); return jsonPatch.apply(document); } catch (IOException | JsonPatchException e) { String message = String.format("Unable to apply patch to document. document: %s, patch: %s", document, patchOperations); throw new PatchApplicationException(message, e); } }
JsonPatchApplier { public JsonNode apply(JsonNode document, List<PatchOperation> patchOperations) throws PatchApplicationException { try { JsonNode patch = mapper.convertValue(patchOperations, JsonNode.class); JsonPatch jsonPatch = JsonPatch.fromJson(patch); return jsonPatch.apply(document); } catch (IOException | JsonPatchException e) { String message = String.format("Unable to apply patch to document. document: %s, patch: %s", document, patchOperations); throw new PatchApplicationException(message, e); } } }
JsonPatchApplier { public JsonNode apply(JsonNode document, List<PatchOperation> patchOperations) throws PatchApplicationException { try { JsonNode patch = mapper.convertValue(patchOperations, JsonNode.class); JsonPatch jsonPatch = JsonPatch.fromJson(patch); return jsonPatch.apply(document); } catch (IOException | JsonPatchException e) { String message = String.format("Unable to apply patch to document. document: %s, patch: %s", document, patchOperations); throw new PatchApplicationException(message, e); } }  }
JsonPatchApplier { public JsonNode apply(JsonNode document, List<PatchOperation> patchOperations) throws PatchApplicationException { try { JsonNode patch = mapper.convertValue(patchOperations, JsonNode.class); JsonPatch jsonPatch = JsonPatch.fromJson(patch); return jsonPatch.apply(document); } catch (IOException | JsonPatchException e) { String message = String.format("Unable to apply patch to document. document: %s, patch: %s", document, patchOperations); throw new PatchApplicationException(message, e); } }  JsonNode apply(JsonNode document, List<PatchOperation> patchOperations); }
JsonPatchApplier { public JsonNode apply(JsonNode document, List<PatchOperation> patchOperations) throws PatchApplicationException { try { JsonNode patch = mapper.convertValue(patchOperations, JsonNode.class); JsonPatch jsonPatch = JsonPatch.fromJson(patch); return jsonPatch.apply(document); } catch (IOException | JsonPatchException e) { String message = String.format("Unable to apply patch to document. document: %s, patch: %s", document, patchOperations); throw new PatchApplicationException(message, e); } }  JsonNode apply(JsonNode document, List<PatchOperation> patchOperations);  }