Skip to content

Commit

Permalink
Fix #1844
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Dec 4, 2017
1 parent 450c1a9 commit 77fd035
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
4 changes: 4 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -722,3 +722,7 @@ Peter Jurkovic (peterjurkovic@github)
* Reported #1823: ClassNameIdResolver doesn't handle resolve Collections$SingletonMap,
Collections$SingletonSet
(2.9.3)

alinakovalenko@github:
* Reported #1844: Map "deep" merge only adds new items, but not override existing values
(2.9.3)
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Project: jackson-databind
(reported by ZeleniJure@github)
#1843: Include name of unsettable property in exception from `SetterlessProperty.set()`
(suggested by andreh7@github)
#1844: Map "deep" merge only adds new items, but not override existing values
(reported by alinakovalenko@github)

2.9.2 (14-Oct-2017)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,17 +665,18 @@ protected final void _readAndUpdate(JsonParser p, DeserializationContext ctxt,
result.put(key, _nullProvider.getNullValue(ctxt));
continue;
}
Object value = result.get(key);
if (value != null) {
valueDes.deserialize(p, ctxt, value);
continue;
}
if (typeDeser == null) {
Object old = result.get(key);
Object value;
if (old != null) {
value = valueDes.deserialize(p, ctxt, old);
} else if (typeDeser == null) {
value = valueDes.deserialize(p, ctxt);
} else {
value = valueDes.deserializeWithType(p, ctxt, typeDeser);
}
result.put(key, value);
if (value != old) {
result.put(key, value);
}
} catch (Exception e) {
wrapAndThrow(e, result, keyStr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public void setMapIntegerInteger(Map<Integer, Integer> mapIntegerInteger) {
this.mapIntegerInteger = mapIntegerInteger;
}

private Map<String, Integer> mapStringInteger = new HashMap<>();
private Map<String, Integer> mapStringInteger = new LinkedHashMap<>();

private Map<Integer, Integer> mapIntegerInteger = new HashMap<>();
private Map<Integer, Integer> mapIntegerInteger = new LinkedHashMap<>();
}

// for [databind#1844]
Expand All @@ -39,9 +39,6 @@ public void testMap1844() throws Exception
final ObjectMapper mapper = newObjectMapper();
mapper.setDefaultMergeable(true);

TestMap1844 testMap = new TestMap1844();
TestMap1844 testMap1 = new TestMap1844();

final String f1 = aposToQuotes(
"{ 'key1' : {\n"
+" '1': 1, '2': 2, '3': 3\n"
Expand All @@ -51,19 +48,22 @@ public void testMap1844() throws Exception
);
final String f2 = aposToQuotes(
"{ 'key1' : {\n"
+" '1': 2, '2': 3, '3': 5\n"
+" '1': 2, '2': 3, '4': 5\n"
+"}, 'key2': {\n"
+" '1': 2, '2': 3, '3': 5\n"
+" '1': 2, '2': 3, '4': 5\n"
+"} }"
);

testMap = mapper.readerForUpdating(testMap).readValue(f1);
testMap1 = mapper.readerForUpdating(testMap1).readValue(f1);
TestMap1844 testMap = mapper.readerFor(TestMap1844.class).readValue(f1);
testMap = mapper.readerForUpdating(testMap).readValue(f2);
testMap1 = mapper.readerForUpdating(testMap1).readValue(f2);
// System.out.println(testMap.getMapIntegerInteger().get(1));
// System.out.println(testMap.getMapStringInteger().get("1"));
assertEquals(testMap.getMapIntegerInteger().get(1), testMap1.getMapIntegerInteger().get(1));
assertEquals(testMap.getMapStringInteger().get("1"), testMap1.getMapStringInteger().get("1"));

assertEquals(Integer.valueOf(2), testMap.getMapStringInteger().get("1"));
assertEquals(Integer.valueOf(3), testMap.getMapStringInteger().get("2"));
assertEquals(Integer.valueOf(3), testMap.getMapStringInteger().get("3"));
assertEquals(Integer.valueOf(5), testMap.getMapStringInteger().get("4"));

assertEquals(Integer.valueOf(2), testMap.getMapIntegerInteger().get(1));
assertEquals(Integer.valueOf(3), testMap.getMapIntegerInteger().get(2));
assertEquals(Integer.valueOf(3), testMap.getMapIntegerInteger().get(3));
assertEquals(Integer.valueOf(5), testMap.getMapIntegerInteger().get(4));
}
}

0 comments on commit 77fd035

Please sign in to comment.