Skip to content

Commit 906a5fd

Browse files
committed
Fix NPE at ObjectMapper#copy with MessagePackFactory
1 parent 1447f8f commit 906a5fd

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/MessagePackFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public MessagePackFactory(MessagePackFactory src)
5858
this.packerConfig = src.packerConfig.clone();
5959
this.reuseResourceInGenerator = src.reuseResourceInGenerator;
6060
this.reuseResourceInParser = src.reuseResourceInParser;
61-
this.extTypeCustomDesers = new ExtensionTypeCustomDeserializers(src.extTypeCustomDesers);
61+
if (src.extTypeCustomDesers != null) {
62+
this.extTypeCustomDesers = new ExtensionTypeCustomDeserializers(src.extTypeCustomDesers);
63+
}
6264
}
6365

6466
public MessagePackFactory setReuseResourceInGenerator(boolean reuseResourceInGenerator)

msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/MessagePackFactoryTest.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.fasterxml.jackson.core.type.TypeReference;
2323
import com.fasterxml.jackson.databind.AnnotationIntrospector;
2424
import com.fasterxml.jackson.databind.ObjectMapper;
25+
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
2526
import org.junit.Test;
2627
import org.msgpack.core.MessagePack;
2728

@@ -58,7 +59,36 @@ public void testCreateParser()
5859
}
5960

6061
@Test
61-
public void copy()
62+
public void copyWithDefaultConfig()
63+
throws IOException
64+
{
65+
MessagePackFactory messagePackFactory = new MessagePackFactory();
66+
ObjectMapper copiedObjectMapper = new ObjectMapper(messagePackFactory).copy();
67+
JsonFactory copiedFactory = copiedObjectMapper.getFactory();
68+
assertThat(copiedFactory, is(instanceOf(MessagePackFactory.class)));
69+
MessagePackFactory copiedMessagePackFactory = (MessagePackFactory) copiedFactory;
70+
71+
assertThat(copiedMessagePackFactory.getPackerConfig().isStr8FormatSupport(), is(true));
72+
73+
assertThat(copiedMessagePackFactory.getExtTypeCustomDesers(), is(nullValue()));
74+
75+
assertThat(copiedMessagePackFactory.isEnabled(JsonGenerator.Feature.AUTO_CLOSE_TARGET), is(true));
76+
assertThat(copiedMessagePackFactory.isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE), is(true));
77+
78+
Collection<AnnotationIntrospector> annotationIntrospectors = copiedObjectMapper.getSerializationConfig().getAnnotationIntrospector().allIntrospectors();
79+
assertThat(annotationIntrospectors.size(), is(1));
80+
assertThat(annotationIntrospectors.stream().findFirst().get(), is(instanceOf(JacksonAnnotationIntrospector.class)));
81+
82+
HashMap<String, Integer> map = new HashMap<>();
83+
map.put("one", 1);
84+
Map<String, Integer> deserialized = copiedObjectMapper
85+
.readValue(objectMapper.writeValueAsBytes(map), new TypeReference<Map<String, Integer>>() {});
86+
assertThat(deserialized.size(), is(1));
87+
assertThat(deserialized.get("one"), is(1));
88+
}
89+
90+
@Test
91+
public void copyWithAdvancedConfig()
6292
throws IOException
6393
{
6494
ExtensionTypeCustomDeserializers extTypeCustomDesers = new ExtensionTypeCustomDeserializers();

0 commit comments

Comments
 (0)