Java 中的 REST API 补丁
REST API PATCH in Java
如果我要在这个 and the RFC 6902 中实施已接受的答案,我是否还需要创建一个 class,其字段包括 op、路径、值和来自?
正如@chrylis 所回答的,我宁愿必须创建一个 class with op, path, value,from 是字段。
您可能不想编写自己的 JSON 补丁解析器。
Java EE 8 现在支持 RFC 6902 with the JSR 374 (JSON-P 1.1): JsonPatch
, JsonPatchBuilder
and JsonPatch.Operation
是您正在寻找的主要类型。
Spring Data REST也支持RFC 6902: PatchConverter<T>
, JsonPatchPatchConverter
, Patch
and PatchOperation
主要类型。
或者,如果您使用 Jackson,您可以考虑 json-patch
库。
更新: 我最近整理了一份 example on how to support JSON Patch and JSON Merge Path in Spring applications. The approach I've used is described in this post.
如果我要在这个
正如@chrylis 所回答的,我宁愿必须创建一个 class with op, path, value,from 是字段。
您可能不想编写自己的 JSON 补丁解析器。
Java EE 8 现在支持 RFC 6902 with the JSR 374 (JSON-P 1.1):
JsonPatch
,JsonPatchBuilder
andJsonPatch.Operation
是您正在寻找的主要类型。Spring Data REST也支持RFC 6902:
PatchConverter<T>
,JsonPatchPatchConverter
,Patch
andPatchOperation
主要类型。或者,如果您使用 Jackson,您可以考虑
json-patch
库。
更新: 我最近整理了一份 example on how to support JSON Patch and JSON Merge Path in Spring applications. The approach I've used is described in this post.