java - Merging Two JSON Documents Using Jackson - Stack Overflow
One way is to use ObjectReader
like so:
MyBean defaults = objectMapper.readValue(defaultJson, MyBean.class); ObjectReader updater = objectMapper.readerForUpdating(defaults); MyBean merged = updater.readValue(overridesJson);
which will combine data from two sources. This only makes a shallow copy, i.e. does not do recursive merge on contained objects (there is a feature request for doing that, not yet implemented).
Otherwise you may need to just read JSON as a tree (JsonNode
), loop over contents and merge manually. This often makes sense anyway since rules of merging are not trivial, and everyone has their own ideas of how merging should work.
Read full article from java - Merging Two JSON Documents Using Jackson - Stack Overflow
No comments:
Post a Comment