Make applyPatch a generic method
This commit is contained in:
@ -26,13 +26,7 @@ public class SigningRequestDocumentController implements SigningRequestDocumentA
|
||||
var document = signingRequestDocumentService.getSigningRequestDocument(id);
|
||||
|
||||
try {
|
||||
JsonNode patchNode = objectMapper.valueToTree(patchOperations);
|
||||
|
||||
JsonPatch jsonPatch = JsonPatch.fromJson(patchNode);
|
||||
|
||||
JsonNode patchedNode = jsonPatch.apply(objectMapper.convertValue(document, JsonNode.class));
|
||||
|
||||
SigningRequestDocument patchedDocument = objectMapper.treeToValue(patchedNode, SigningRequestDocument.class);
|
||||
var patchedDocument = applyPatch(patchOperations, document, SigningRequestDocument.class);
|
||||
|
||||
signingRequestDocumentService.updateSigningRequestDocument(patchedDocument);
|
||||
|
||||
@ -44,4 +38,14 @@ public class SigningRequestDocumentController implements SigningRequestDocumentA
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T applyPatch(List<PatchOperation> patchOperations, T object, Class<T> entityType) throws JsonPatchException, IOException {
|
||||
JsonNode patchNode = objectMapper.valueToTree(patchOperations);
|
||||
JsonPatch jsonPatch = JsonPatch.fromJson(patchNode);
|
||||
|
||||
// Convert the entity to JsonNode and apply the patch
|
||||
JsonNode entityNode = objectMapper.convertValue(object, JsonNode.class);
|
||||
JsonNode patchedNode = jsonPatch.apply(entityNode);
|
||||
|
||||
return objectMapper.treeToValue(patchedNode, entityType);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user