Library used: com.github.fge.jsonpatch
And I have one PATCH endpoint which accepts the String of json-patch operations.
public Employee patchEmployee(String patchOperations, String empId);
This method then does the required conversion to JsonPatch and all the necessary steps to apply the patch. This part is working fine when an array of Json-patch operations is sent to it in string format as a payload.
But to call this API from a rest client, I need to construct the array of json-patch operations in String format.
I am trying to use the JsonPatchOperation like:
JsonPatchOperation replaceName = new ReplaceOperation(new JsonPointer("/name"), nameNode);
JsonPatchOperation replaceSubject = new ReplaceOperation(new JsonPointer("/subject"), subjectNode);
Using this method I can apply the operations to the Employee object directly, but as the endpoint accepts the String, I am not getting how to convert these operations to String format like:
[
{"op": "replace", "path": "/name","value":"John" },
{"op": "replace", "path": "/subject","value":"Science" }
]
Is there any way we can construct this payload apart from manually creating the Json string?