{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"id": {
"type": "string"
},
"i": {
"type": "integer"
},
"p": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"id": {
"type": "string"
},
"i": {
"type": "integer"
},
"p1": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"id": {
"type": "string"
},
"i": {
"type": "integer"
}
}
}
}
}
},
"classname": "com.tibco.tea.agent.Person"
}
我有上面生成的架构,我想对其进行一些修改。正如您所看到的,我已将对象嵌套在该架构中。我想为每个对象插入一个“classname”属性。任何人都可以建议我如何使用 jackson 2.3.0 来遍历这个模式并按照上面提到的方式操作它。
如果节点是对象,您可以将它们转换为ObjectNode
并使用put
方法添加所需的键/值对。
JSON = // stuff you have in example
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(JSON);
// using root node for this example
if (jsonNode.isObject()) {
((ObjectNode) jsonNode).put("classname", "com.stackoverflow.Cheese");
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)