Skip to content

Commit

Permalink
Fix #4922: @JsonMerge with custom map (#4925)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Jan 26, 2025
1 parent 53f3469 commit 681e399
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Project: jackson-databind
#4908: Deserialization behavior change with @JsonCreator and
@ConstructorProperties between 2.17 and 2.18
(reported by Gustavo B)
#4922: Failing `@JsonMerge` with a custom Map
(reported by @nlisker)

2.18.2 (27-Nov-2024)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -979,12 +979,6 @@ public JsonDeserializer<?> createMapDeserializer(DeserializationContext ctxt,
mapClass = type.getRawClass();
// But if so, also need to re-check creators...
beanDesc = config.introspectForCreation(type);
} else {
// [databind#292]: Actually, may be fine, but only if polymorphic deser enabled
if (type.getTypeHandler() == null) {
throw new IllegalArgumentException("Cannot find a deserializer for non-concrete Map type "+type);
}
deser = AbstractDeserializer.constructForNonPOJO(beanDesc);
}
} else {
// 10-Jan-2017, tatu: `java.util.Collections` types need help:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.fasterxml.jackson.databind.deser.merge;

import java.util.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonMerge;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;

import static org.junit.jupiter.api.Assertions.*;

@SuppressWarnings("serial")
public class CustomMapMerge4922Test
extends DatabindTestUtil
{
// [databind#4922]
interface MyMap4922<K, V> extends Map<K, V> {}

static class MapImpl<K, V> extends HashMap<K, V> implements MyMap4922<K, V> {}

static class MergeMap4922 {
@JsonMerge // either here
public MyMap4922<Integer, String> map = new MapImpl<>();
}

private final ObjectMapper MAPPER = newJsonMapper();

// [databind#4922]: Merge for custom maps fails
@Test
void testJDKMapperReading() throws Exception {
MergeMap4922 input = new MergeMap4922();
input.map.put(3, "ADS");

String json = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(input);
MergeMap4922 merge2 = MAPPER.readValue(json, MergeMap4922.class);
assertNotNull(merge2);
}

}

0 comments on commit 681e399

Please sign in to comment.