I have two JsonNode objects, A and B, which both contain an identical field, "segments". I need to take the content from JsonNode object A and append it to the content from B. I need both the values from A and B in the final object.
My code right now takes the right content from A, but it replaces everything from B. Can anyone help me with a solution? In the end, I need to obtain an object like C, as you can see below.
public static JsonNode merge(JsonNode mainNode, JsonNode updateNode) {
JsonNode segmentedConfigs = updateNode.get("segments");
((ObjectNode) mainNode).put("segments", segmentedConfigs);
return mainNode;
}
JsonNode A:
{
"segments": {
"A": {},
"B": {},
"C": {}
},
"enabled": false,
"configStickyByClub": false,
"sinks": {}
}
JsonNode B:
{
"segments": {
"D": {},
"E": {},
"F": {}
},
"enabled": false,
"configStickyByClub": false,
"sinks": {}
}
JsonNode C:
{
"segments": {
"A": {},
"B": {},
"C": {},
"D": {},
"E": {},
"F": {}
},
"enabled": false,
"configStickyByClub": false,
"sinks": {}
}