Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix NPE at ObjectMapper#copy with MessagePackFactory
  • Loading branch information
komamitsu committed Apr 14, 2018
commit 906a5fdb3b3f4c8496dd2c695c065e4844c0dc46
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public MessagePackFactory(MessagePackFactory src)
this.packerConfig = src.packerConfig.clone();
this.reuseResourceInGenerator = src.reuseResourceInGenerator;
this.reuseResourceInParser = src.reuseResourceInParser;
this.extTypeCustomDesers = new ExtensionTypeCustomDeserializers(src.extTypeCustomDesers);
if (src.extTypeCustomDesers != null) {
this.extTypeCustomDesers = new ExtensionTypeCustomDeserializers(src.extTypeCustomDesers);
}
}

public MessagePackFactory setReuseResourceInGenerator(boolean reuseResourceInGenerator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import org.junit.Test;
import org.msgpack.core.MessagePack;

Expand Down Expand Up @@ -58,7 +59,36 @@ public void testCreateParser()
}

@Test
public void copy()
public void copyWithDefaultConfig()
throws IOException
{
MessagePackFactory messagePackFactory = new MessagePackFactory();
ObjectMapper copiedObjectMapper = new ObjectMapper(messagePackFactory).copy();
JsonFactory copiedFactory = copiedObjectMapper.getFactory();
assertThat(copiedFactory, is(instanceOf(MessagePackFactory.class)));
MessagePackFactory copiedMessagePackFactory = (MessagePackFactory) copiedFactory;

assertThat(copiedMessagePackFactory.getPackerConfig().isStr8FormatSupport(), is(true));

assertThat(copiedMessagePackFactory.getExtTypeCustomDesers(), is(nullValue()));

assertThat(copiedMessagePackFactory.isEnabled(JsonGenerator.Feature.AUTO_CLOSE_TARGET), is(true));
assertThat(copiedMessagePackFactory.isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE), is(true));

Collection<AnnotationIntrospector> annotationIntrospectors = copiedObjectMapper.getSerializationConfig().getAnnotationIntrospector().allIntrospectors();
assertThat(annotationIntrospectors.size(), is(1));
assertThat(annotationIntrospectors.stream().findFirst().get(), is(instanceOf(JacksonAnnotationIntrospector.class)));

HashMap<String, Integer> map = new HashMap<>();
map.put("one", 1);
Map<String, Integer> deserialized = copiedObjectMapper
.readValue(objectMapper.writeValueAsBytes(map), new TypeReference<Map<String, Integer>>() {});
assertThat(deserialized.size(), is(1));
assertThat(deserialized.get("one"), is(1));
}

@Test
public void copyWithAdvancedConfig()
throws IOException
{
ExtensionTypeCustomDeserializers extTypeCustomDesers = new ExtensionTypeCustomDeserializers();
Expand Down