【发布时间】:2021-07-15 15:19:25
【问题描述】:
我低于 JSON,我想从中更新几个字段
{
"process": "my-process",
"pod": "some-pod",
"org": "some-org",
"config": {
"version": "436_601_83.0.0",
"path": "companyName/ccg",
"description": "update the version",
"dependencies": null
}
}
使用带有以下 JSONPatch 有效负载 API 的邮递员 PATCH API 调用工作正常
[
{
"path": "/config/version",
"op": "replace",
"value": "436_605_83.0.0"
},
{
"path": "/config/description",
"op": "replace",
"value": "foo bar"
}
]
但是,我想用 Java 实现同样的功能.. 我试过了
JsonPatch jsonPatch = new JsonPatch(
Arrays.asList(
new ReplaceOperation(JsonPointer.of("/config/version"),
new TextNode("436_605_83.0.0"))
)
);
计算结果为:
[{"op":"replace","path":"/~1config~1version","value":"436_605_83.0.0"}]
该文档提到http://jsonpatch.com/#json-pointer 我们必须使用~0 和~1 转义字符但还没有运气,我使用~1 转义/ 即"~1config~1version" 但它的计算结果为"/~01config~01version"
【问题讨论】:
-
1) 这是哪种编程语言? 2)根据1,你从哪里得到
JsonPointer? -
我正在尝试使用 Java
标签: java json rest json-patch http-patch