0
|
1 # MessagePack for Java
|
|
2
|
|
3 QuickStart for msgpack-java is available [here](https://github.com/msgpack/msgpack-java/wiki/QuickStart).
|
|
4
|
|
5 ## How to install
|
|
6
|
|
7 You can install msgpack via maven:
|
|
8
|
|
9 <dependencies>
|
|
10 ...
|
|
11 <dependency>
|
|
12 <groupId>org.msgpack</groupId>
|
|
13 <artifactId>msgpack</artifactId>
|
|
14 <version>${msgpack.version}</version>
|
|
15 </dependency>
|
|
16 ...
|
|
17 </dependencies>
|
|
18
|
|
19 ## Simple Serialization/Deserialization/Duck Typing using Value
|
|
20
|
|
21 // Create serialize objects.
|
|
22 List<String> src = new ArrayList<String>();
|
|
23 src.add("msgpack");
|
|
24 src.add("kumofs");
|
|
25 src.add("viver");
|
|
26
|
|
27 MessagePack msgpack = new MessagePack();
|
|
28 // Serialize
|
|
29 byte[] raw = msgpack.write(src);
|
|
30
|
|
31 // Deserialize directly using a template
|
|
32 List<String> dst1 = msgpack.read(raw, Templates.tList(Templates.TString));
|
|
33 System.out.println(dst1.get(0));
|
|
34 System.out.println(dst1.get(1));
|
|
35 System.out.println(dst1.get(2));
|
|
36
|
|
37 // Or, Deserialze to Value then convert type.
|
|
38 Value dynamic = msgpack.read(raw);
|
|
39 List<String> dst2 = new Converter(dynamic)
|
|
40 .read(Templates.tList(Templates.TString));
|
|
41 System.out.println(dst2.get(0));
|
|
42 System.out.println(dst2.get(1));
|
|
43 System.out.println(dst2.get(2));
|
|
44
|
|
45
|
|
46
|