Skip to content

Commit eb8c072

Browse files
committed
Merge branch '2.19'
2 parents c4406ec + 0e9db3d commit eb8c072

File tree

5 files changed

+72
-3
lines changed

5 files changed

+72
-3
lines changed

release-notes/CREDITS-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,9 @@ wrongwrong (@k163377)
18501850
* Contributed #4749: Fixed problem in StdDelegatingSerializer#serializeWithType where final
18511851
serializer lookup was done on the pre-converted value when _delegateSerializer was null
18521852
(2.18.1)
1853+
* Reported #4878: When serializing a Map via Converter(StdDelegatingSerializer),
1854+
a NullPointerException is thrown due to missing key serializer
1855+
(2.18.3)
18531856

18541857
Bernd Ahlers (@bernd)
18551858
* Reported #4742: Deserialization with Builder, External type id, `@JsonCreator` failing

release-notes/VERSION-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ Project: jackson-databind
5858
multiple constructors since 2.18
5959
(reported by Tomáš P)
6060
(fix by Joo-Hyuk K, @cowtowncoder)
61+
#4878: When serializing a Map via Converter(StdDelegatingSerializer),
62+
a NullPointerException is thrown due to missing key serializer
63+
(reported by @wrongwrong)
6164
#4908: Deserialization behavior change with @JsonCreator and
6265
@ConstructorProperties between 2.17 and 2.18
6366
(reported by Gustavo B)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package tools.jackson.databind.convert;
2+
3+
import java.util.Collections;
4+
import java.util.Map;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
import com.fasterxml.jackson.annotation.JsonFormat;
9+
10+
import tools.jackson.databind.*;
11+
import tools.jackson.databind.module.SimpleModule;
12+
import tools.jackson.databind.module.SimpleSerializers;
13+
import tools.jackson.databind.ser.std.StdDelegatingSerializer;
14+
import tools.jackson.databind.testutil.DatabindTestUtil;
15+
import tools.jackson.databind.util.StdConverter;
16+
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
19+
public class MapConversion4878Test extends DatabindTestUtil
20+
{
21+
// [databind#4878]
22+
static class MapWrapper4878 {
23+
final Map<String, Object> value;
24+
25+
MapWrapper4878(Map<String, Object> value) {
26+
this.value = value;
27+
}
28+
}
29+
30+
static class WrapperConverter4878 extends StdConverter<MapWrapper4878, Object> {
31+
@Override
32+
public Object convert(MapWrapper4878 value) {
33+
return value.value;
34+
}
35+
}
36+
37+
@SuppressWarnings("serial")
38+
static class Serializers4878 extends SimpleSerializers {
39+
@Override
40+
public ValueSerializer<?> findSerializer(SerializationConfig config,
41+
JavaType type, BeanDescription beanDesc, JsonFormat.Value formatOverrides) {
42+
Class<?> rawClass = type.getRawClass();
43+
if (MapWrapper4878.class.isAssignableFrom(rawClass)) {
44+
return new StdDelegatingSerializer(new WrapperConverter4878());
45+
}
46+
return super.findSerializer(config, type, beanDesc, formatOverrides);
47+
}
48+
}
49+
50+
// [databind#4878]
51+
@Test
52+
public void testMapConverter() throws Exception
53+
{
54+
SimpleModule sm = new SimpleModule();
55+
sm.setSerializers(new Serializers4878());
56+
final ObjectMapper mapper = jsonMapperBuilder()
57+
.addModule(sm)
58+
.build();
59+
String json = mapper.writeValueAsString(new MapWrapper4878(Collections.singletonMap("a", 1)));
60+
assertEquals(a2q("{'a':1}"), json);
61+
}
62+
}

src/test/java/tools/jackson/databind/convert/MapConversionsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@
1515

1616
public class MapConversionsTest
1717
{
18-
final ObjectMapper MAPPER = newJsonMapper();
19-
2018
enum AB { A, B; }
2119

2220
static class Bean {
2321
public Integer A;
2422
public String B;
2523
}
2624

27-
// [Issue#287]
25+
// [databind#287]
2826

2927
@JsonSerialize(converter=RequestConverter.class)
3028
static class Request {
@@ -50,6 +48,8 @@ public Map<String,Object> convert(final Request value) {
5048
/**********************************************************
5149
*/
5250

51+
private final ObjectMapper MAPPER = newJsonMapper();
52+
5353
/**
5454
* Test that verifies that we can go between couple of types of Maps...
5555
*/

src/test/java/tools/jackson/databind/records/RecordJsonSerDeser188Test.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public void serialize(String value, JsonGenerator jgen, SerializationContext pro
4343
}
4444
}
4545

46+
@SuppressWarnings("serial")
4647
static class PrefixStringDeserializer extends StdScalarDeserializer<String>
4748
{
4849
protected PrefixStringDeserializer() {

0 commit comments

Comments
 (0)