@@ -58,11 +58,17 @@ Only thing you need to do is to instantiate `MessagePackFactory` and pass it to
5858 System . out. println(deserialized. getName()); // => komamitsu
5959```
6060
61+ Or more easily:
62+
63+ ``` java
64+ ObjectMapper objectMapper = new MessagePackMapper ();
65+ ```
66+
6167### Serialization/Deserialization of List
6268
6369``` java
6470 // Instantiate ObjectMapper for MessagePack
65- ObjectMapper objectMapper = new ObjectMapper ( new MessagePackFactory () );
71+ ObjectMapper objectMapper = new MessagePackMapper ( );
6672
6773 // Serialize a List to byte array
6874 List<Object > list = new ArrayList<> ();
@@ -80,7 +86,7 @@ Only thing you need to do is to instantiate `MessagePackFactory` and pass it to
8086
8187``` java
8288 // Instantiate ObjectMapper for MessagePack
83- ObjectMapper objectMapper = new ObjectMapper ( new MessagePackFactory () );
89+ ObjectMapper objectMapper = MessagePackMapper( );
8490
8591 // Serialize a Map to byte array
8692 Map<String , Object > map = new HashMap<> ();
@@ -146,7 +152,7 @@ On the other hand, jackson-databind serializes and deserializes a POJO as a key-
146152But if you want to make this library handle POJOs in the same way as msgpack-java:0.6 or earlier, you can use ` JsonArrayFormat ` like this:
147153
148154``` java
149- ObjectMapper objectMapper = new ObjectMapper ( new MessagePackFactory () );
155+ ObjectMapper objectMapper = new MessagePackMapper ( );
150156 objectMapper. setAnnotationIntrospector(new JsonArrayFormat ());
151157```
152158
@@ -156,7 +162,7 @@ But if you want to make this library handle POJOs in the same way as msgpack-jav
156162
157163``` java
158164 OutputStream out = new FileOutputStream (tempFile);
159- ObjectMapper objectMapper = new ObjectMapper ( new MessagePackFactory () );
165+ ObjectMapper objectMapper = new MessagePackMapper ( );
160166 objectMapper. configure(JsonGenerator . Feature . AUTO_CLOSE_TARGET , false );
161167
162168 objectMapper. writeValue(out, 1 );
@@ -181,7 +187,7 @@ But if you want to make this library handle POJOs in the same way as msgpack-jav
181187 packer. close();
182188
183189 FileInputStream in = new FileInputStream (tempFile);
184- ObjectMapper objectMapper = new ObjectMapper ( new MessagePackFactory () );
190+ ObjectMapper objectMapper = new MessagePackMapper ( );
185191 objectMapper. configure(JsonParser . Feature . AUTO_CLOSE_SOURCE , false );
186192 System . out. println(objectMapper. readValue(in, Integer . class));
187193 System . out. println(objectMapper. readValue(in, String . class));
@@ -194,7 +200,7 @@ Old msgpack-java (e.g 0.6.7) doesn't support MessagePack str8 type. When your ap
194200
195201``` java
196202 MessagePack . PackerConfig config = new MessagePack .PackerConfig (). withStr8FormatSupport(false );
197- ObjectMapper mapperWithConfig = new ObjectMapper (new MessagePackFactory (config));
203+ ObjectMapper mapperWithConfig = new MessagePackMapper (new MessagePackFactory (config));
198204 // This string is serialized as bin8 type
199205 byte [] resultWithoutStr8Format = mapperWithConfig. writeValueAsBytes(str8LengthString);
200206```
@@ -211,7 +217,7 @@ When you want to use non-String value as a key of Map, use `MessagePackKeySerial
211217
212218 intMap. put(42 , " Hello" );
213219
214- ObjectMapper objectMapper = new ObjectMapper ( new MessagePackFactory () );
220+ ObjectMapper objectMapper = new MessagePackMapper ( );
215221 byte [] bytes = objectMapper. writeValueAsBytes(intMap);
216222
217223 Map<Integer , String > deserialized = objectMapper. readValue(bytes, new TypeReference<Map<Integer , String > > () {});
@@ -407,15 +413,15 @@ When you serialize an object that has a nested object also serializing with Obje
407413 @Test
408414 public void testNestedSerialization() throws Exception
409415 {
410- ObjectMapper objectMapper = new ObjectMapper ( new MessagePackFactory () );
416+ ObjectMapper objectMapper = new MessagePackMapper ( );
411417 objectMapper. writeValueAsBytes(new OuterClass ());
412418 }
413419
414420 public class OuterClass
415421 {
416422 public String getInner () throws JsonProcessingException
417423 {
418- ObjectMapper m = new ObjectMapper ( new MessagePackFactory () );
424+ ObjectMapper m = new MessagePackMapper ( );
419425 m. writeValueAsBytes(new InnerClass ());
420426 return " EFG" ;
421427 }
0 commit comments