|
57 | 57 | * serialization. |
58 | 58 | * </p> |
59 | 59 | * |
60 | | - * <h3>Install</h3> |
| 60 | + * <h3>How to Install</h3> |
61 | 61 | * |
62 | 62 | * <p> |
63 | 63 | * The official Maven2 repository for MessagePack for Java is located here. <a |
|
201 | 201 | * values of various types as follows. They enable serializing/deserializing |
202 | 202 | * values of various types like values of primitive types, values of primitive |
203 | 203 | * wrapper classes, <code>String</code> objects, <code>byte[]</code> objects, |
204 | | - * <code>ByteBuffer</code> objects, <code>List</code> objects, </code>Map</code> |
205 | | - * objects and so on. As mentioned above, they also enable |
206 | | - * serializing/deserizing objects of your own classes annotated by |
| 204 | + * <code>ByteBuffer</code> objects and so on. As mentioned above, they also |
| 205 | + * enable serializing/deserizing objects of your own classes annotated by |
207 | 206 | * <code>@Message</code>. |
208 | 207 | * </p> |
209 | 208 | * |
|
239 | 238 | * packer.write("MesagePack"); // String object |
240 | 239 | * packer.write(java.nio.ByteBufer.wrap(new byte[] { 0x30, 0x31, 0x32 })); // ByteBuffer object |
241 | 240 | * packer.write(java.math.BigInteger.ONE); // BigInteger object |
242 | | - * java.util.List<String> list = new java.util.ArrayList<String>(); |
243 | | - * list.add("msgpack"); |
244 | | - * list.add("for"); |
245 | | - * list.add("java"); |
246 | | - * packer.write(list); // List object |
247 | | - * java.util.Map<String, String> map = new java.util.HashMap<String, String>(); |
248 | | - * map.put("sadayuki", "furuhashi"); |
249 | | - * map.put("muga", "nishizawa"); |
250 | | - * packer.write(map); // Map object |
251 | 241 | * |
252 | 242 | * // |
253 | 243 | * // deserialization |
|
277 | 267 | * String ws = unpacker.read(String.class); |
278 | 268 | * java.nio.ByteBuffer buf = unpacker.read(java.nio.ByteBuffer.class); |
279 | 269 | * java.math.BigInteger bi = unpacker.read(java.math.BigInteger.class); |
280 | | - * java.util.List<String> dstList = new java.util.ArrayList<String>(); |
281 | | - * dstList = unpacker.read(dstList); |
282 | | - * java.util.Map<String, String> dstMap = new java.util.HashMap<String, String>(); |
283 | | - * dstMap = unpacker.read(dstMap); |
284 | 270 | * } |
285 | 271 | * } |
286 | 272 | * </pre> |
|
307 | 293 | * <code>read(byte[].class)</code>) method. |
308 | 294 | * </p> |
309 | 295 | * |
| 296 | + * <h3><code>List</code>, <code>Map</code> objects Serialization/Deserialization |
| 297 | + * </h3> |
| 298 | + * |
| 299 | + * <p> |
| 300 | + * You can serialize <code>List</code> and <code>Map</code> objects with |
| 301 | + * {@link org.msgpack.template.Template} objects, which are pairs of |
| 302 | + * serializer/deserializer. The type of elements in <code>List</code> object |
| 303 | + * needs to be specified to <code>Template</code> object for effective |
| 304 | + * serialization/deserialization. Types of keys and values in <code>Map</code> |
| 305 | + * object also need to be specified to <code>Template</code> object. |
| 306 | + * </p> |
| 307 | + * |
| 308 | + * <pre> |
| 309 | + * import static org.msgpack.template.Templates.tList; |
| 310 | + * import static org.msgpack.template.Templates.tMap; |
| 311 | + * import static org.msgpack.template.Templates.TString; |
| 312 | + * |
| 313 | + * public class Main4 { |
| 314 | + * public static void main(String[] args) { |
| 315 | + * MessagePack msgpack = new MessagePack(); |
| 316 | + * |
| 317 | + * // create templates for serializing/deserializing List and Map objects |
| 318 | + * org.msgpack.template.Template listTmpl = tList(TString); |
| 319 | + * org.msgpack.template.Template mapTmpl = tMap(TString, TString); |
| 320 | + * |
| 321 | + * // |
| 322 | + * // serialization |
| 323 | + * // |
| 324 | + * |
| 325 | + * ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 326 | + * Packer packer = msgpack.createPacker(out); |
| 327 | + * |
| 328 | + * // serialize List object |
| 329 | + * java.util.List<String> list = new java.util.ArrayList<String>(); |
| 330 | + * list.add("msgpack"); |
| 331 | + * list.add("for"); |
| 332 | + * list.add("java"); |
| 333 | + * packer.write(list, listTmpl); // List object |
| 334 | + * |
| 335 | + * // serialize Map object |
| 336 | + * java.util.Map<String, String> map = new java.util.HashMap<String, String>(); |
| 337 | + * map.put("sadayuki", "furuhashi"); |
| 338 | + * map.put("muga", "nishizawa"); |
| 339 | + * packer.write(map, mapTmpl); // Map object |
| 340 | + * |
| 341 | + * // |
| 342 | + * // deserialization |
| 343 | + * // |
| 344 | + * |
| 345 | + * byte[] bytes = out.toByteArray(); |
| 346 | + * ByteArrayInputStream in = new ByteArrayInputStream(bytes); |
| 347 | + * Unpacker unpacker = msgpack.createUnpacker(in); |
| 348 | + * |
| 349 | + * // to List object |
| 350 | + * dstList = unpacker.read(dstList, listTmpl); |
| 351 | + * |
| 352 | + * // to Map object |
| 353 | + * dstMap = unpacker.read(dstMap, mapTmpl); |
| 354 | + * } |
| 355 | + * } |
| 356 | + * </pre> |
| 357 | + * |
310 | 358 | * <h3>Without Annotations</h3> |
311 | 359 | * |
312 | 360 | * <p> |
|
0 commit comments