|
22 | 22 | import com.fasterxml.jackson.core.type.TypeReference; |
23 | 23 | import com.fasterxml.jackson.databind.AnnotationIntrospector; |
24 | 24 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 25 | +import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; |
25 | 26 | import org.junit.Test; |
26 | 27 | import org.msgpack.core.MessagePack; |
27 | 28 |
|
@@ -58,7 +59,36 @@ public void testCreateParser() |
58 | 59 | } |
59 | 60 |
|
60 | 61 | @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() |
62 | 92 | throws IOException |
63 | 93 | { |
64 | 94 | ExtensionTypeCustomDeserializers extTypeCustomDesers = new ExtensionTypeCustomDeserializers(); |
|
0 commit comments