Reputation: 284
Java String which I retrieved from the database:
[
{ "op": "replace", "path": "/baz", "value": "boo" },
{ "op": "add", "path": "/hello", "value": ["world"] },
{ "op": "remove", "path": "/foo" }
]
How can I convert it to a JsonPatch
object?
I am using com.github.fge.jsonpatch
library.
Upvotes: 2
Views: 2562
Reputation: 9336
Based on JSON Patch documentation, you can build a JsonPatch instance using Jackson deserialization.
String json = "...";
final ObjectMapper mapper = new ObjectMapper();
final InputStream in = new ByteArrayInputStream(json.getBytes());
final JsonPatch patch = mapper.readValue(in, JsonPatch.class);
Upvotes: 3