Skip to content

Commit 681e399

Browse files
authored
Fix #4922: @JsonMerge with custom map (#4925)
1 parent 53f3469 commit 681e399

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Project: jackson-databind
2121
#4908: Deserialization behavior change with @JsonCreator and
2222
@ConstructorProperties between 2.17 and 2.18
2323
(reported by Gustavo B)
24+
#4922: Failing `@JsonMerge` with a custom Map
25+
(reported by @nlisker)
2426

2527
2.18.2 (27-Nov-2024)
2628

src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -979,12 +979,6 @@ public JsonDeserializer<?> createMapDeserializer(DeserializationContext ctxt,
979979
mapClass = type.getRawClass();
980980
// But if so, also need to re-check creators...
981981
beanDesc = config.introspectForCreation(type);
982-
} else {
983-
// [databind#292]: Actually, may be fine, but only if polymorphic deser enabled
984-
if (type.getTypeHandler() == null) {
985-
throw new IllegalArgumentException("Cannot find a deserializer for non-concrete Map type "+type);
986-
}
987-
deser = AbstractDeserializer.constructForNonPOJO(beanDesc);
988982
}
989983
} else {
990984
// 10-Jan-2017, tatu: `java.util.Collections` types need help:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.fasterxml.jackson.databind.deser.merge;
2+
3+
import java.util.*;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import com.fasterxml.jackson.annotation.JsonMerge;
8+
import com.fasterxml.jackson.databind.ObjectMapper;
9+
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
10+
11+
import static org.junit.jupiter.api.Assertions.*;
12+
13+
@SuppressWarnings("serial")
14+
public class CustomMapMerge4922Test
15+
extends DatabindTestUtil
16+
{
17+
// [databind#4922]
18+
interface MyMap4922<K, V> extends Map<K, V> {}
19+
20+
static class MapImpl<K, V> extends HashMap<K, V> implements MyMap4922<K, V> {}
21+
22+
static class MergeMap4922 {
23+
@JsonMerge // either here
24+
public MyMap4922<Integer, String> map = new MapImpl<>();
25+
}
26+
27+
private final ObjectMapper MAPPER = newJsonMapper();
28+
29+
// [databind#4922]: Merge for custom maps fails
30+
@Test
31+
void testJDKMapperReading() throws Exception {
32+
MergeMap4922 input = new MergeMap4922();
33+
input.map.put(3, "ADS");
34+
35+
String json = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(input);
36+
MergeMap4922 merge2 = MAPPER.readValue(json, MergeMap4922.class);
37+
assertNotNull(merge2);
38+
}
39+
40+
}

0 commit comments

Comments
 (0)