Deep merge for `JsonNode` using `ObjectReader.readTree()`
See original GitHub issueIs your feature request related to a problem? Please describe.
Describe the solution you’d like
Ability to deep merge two JsonNode
objects, and/or to deserialize a stream by updating an existing JsonNode
rather than creating a new one.
Usage example
var mapper = new ObjectMapper();
var node1 = mapper.readTree("{\"root\":{\"a\":\"aaa\",\"foo\":\"hello\"}}");
var node2 = mapper.readerForUpdating(node1)
.readTree("{\"root\":{\"b\":\"bbb\",\"foo\":\"goodbye\"}}");
Additional context
https://github.com/FasterXML/jackson-databind/issues/584 implies that this capability exists, but it does not appear to be functioning propery for JsonNode
. There also doesn’t seem to be a way to specify shallow or deep merge using the tree API readerForUpdating()
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Merging Two JSON Documents Using Jackson - Stack Overflow
Inspired by StaxMans answer I implemented this merging method. public static JsonNode merge(JsonNode mainNode, JsonNode updateNode) { Iterator<String> ...
Read more >Jackson JSON - Deep merging with @JsonMerge Annotation
Starting Jackson 2.9 we can use @JsonMerge annotation on object fields to update nested fields with JSON input. In other words now we...
Read more >Working with Tree Model Nodes in Jackson - Baeldung
This tutorial will focus on working with tree model nodes in Jackson. We'll use JsonNode for various conversions as well as adding, ...
Read more >ObjectMapper (jackson-databind 2.8.0 API) - FasterXML
Method to deserialize JSON content as tree expressed using set of JsonNode instances. <T extends TreeNode> T, readTree(JsonParser p). Method to deserialize JSON ......
Read more >Security update for jackson-databind, jackson-dataformats ...
+ Deep merge for 'JsonNode' using 'ObjectReader.readTree()' + IllegalArgumentException: Conflicting setter definitions for property with ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks @cowtowncoder for the quick reply! I’ve created a repo https://github.com/sirianni/jsonMerge with a failing unit test.
Ah I had a silly mistake, got it now: