如何将 String 转换为 JsonPatch?
How to convert String to JsonPatch?
Java 我从数据库中检索到的字符串:
[
{ "op": "replace", "path": "/baz", "value": "boo" },
{ "op": "add", "path": "/hello", "value": ["world"] },
{ "op": "remove", "path": "/foo" }
]
如何将其转换为 JsonPatch
对象?
我正在使用 com.github.fge.jsonpatch
库。
根据JSON补丁文档,您可以使用Jackson反序列化构建一个JsonPatch实例。
String json = "...";
final ObjectMapper mapper = new ObjectMapper();
final InputStream in = new ByteArrayInputStream(json.getBytes());
final JsonPatch patch = mapper.readValue(in, JsonPatch.class);
Java 我从数据库中检索到的字符串:
[
{ "op": "replace", "path": "/baz", "value": "boo" },
{ "op": "add", "path": "/hello", "value": ["world"] },
{ "op": "remove", "path": "/foo" }
]
如何将其转换为 JsonPatch
对象?
我正在使用 com.github.fge.jsonpatch
库。
根据JSON补丁文档,您可以使用Jackson反序列化构建一个JsonPatch实例。
String json = "...";
final ObjectMapper mapper = new ObjectMapper();
final InputStream in = new ByteArrayInputStream(json.getBytes());
final JsonPatch patch = mapper.readValue(in, JsonPatch.class);