Is it possible to merge two JSON documents with the Jackson JSON library? I am basically using the Jackson mapper with simple Java Maps.
I’ve tried to search in Google and Jackson’s documentation but couldn’t find anything.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One way is to use
ObjectReaderlike so:which will combine data from two sources. This only makes a shallow copy, i.e. does not do recursive merge on contained objects.
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.EDIT: (03-Apr-2017)
As per @Fernando Correia’s comment, there is actually a new feature added in upcoming Jackson 2.9 (to be released in April or May 2017) that does allow deep merging, finally.