jackson-databind
jackson-databind copied to clipboard
ConfigOverrides for merging are not applied for items inside containers
Currently, there is no way to specify different merge behaviors for array-like types and Map
s if one of the types is used as a container and the other one for the nested items. If either a ConfigOverride
for merging is set for the type of the container class or @JsonMerge
is set directly on the container property, the merge behavior for the container type is always applied to its items as well.
Expected behavior
ConfigOverride
s should apply to container items as long as there is no other config with precedence.
Example (List inside Map)
class SomePojo {
Map<String, List<Integer>> someMap;
}
// serialization config
ObjectMapper mapper = new ObjectMapper();
mapper.setDefaultMergeable(false); // default
mapper.configOverride(Map.class).setMergeable(true);
mapper.configOverride(List.class).setMergeable(false); // this has no effect for Lists inside Maps
Expected result:
{"someMap: {"list": [1, 2, 3]}}
+ {"someMap: {"list": [4, 5, 6]}}
=> {"someMap: {"list": [4, 5, 6]}}
Actual result:
{"someMap: {"list": [1, 2, 3]}}
+ {"someMap: {"list": [4, 5, 6]}}
=> {"someMap: {"list": [1, 2, 3, 4, 5, 6]}}
The override for List
is not applied to nested items. Merging is still enabled for the them despite of using configOverride(List.class).setMergeable(false)
.
Test case
https://github.com/dgerhardt/test-case-jackson-jsonmerge/blob/master/src/test/java/JacksonJsonMergeNested.java
Related discussion
https://gitter.im/FasterXML/jackson-databind?at=60e6fef482dd9050f5dd3008