Using Jackson, I'm creating a Json object like this:
{"A": {
"B": {
"C": {
"D": 1
}
}
}}
with the next code
ObjectNode rootNode = JsonNodeFactory.instance.objectNode();
ObjectNode aNode = JsonNodeFactory.instance.objectNode();
ObjectNode bNode = JsonNodeFactory.instance.objectNode();
ObjectNode cNode = JsonNodeFactory.instance.objectNode();
cNode.put("D", 1);
bNode.set("C", cNode);
aNode.set("B", bNode);
rootNode.set("A", aNode);
Is there a more simple way to create it? something like:
ObjectNode rootNode = JsonNodeFactory.instance.objectNode();
rootNode.set("A/B/C/D",1);
Also reading a similar object is there a simply way to get the value of "D"?
Yes, you can create nested structures with this:
ObjectNode root = JsonNodeFactory.instance.objectNode();
root.with("A").with("B").with("C").put("D", 1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With