Samples JDK
Sample.java
1 package com.freemindcafe.serialization.sample2;
2 
3 import java.util.HashMap;
4 import java.util.Map;
5 
7 
8 public class Sample {
9 
10  @org.junit.Test
11  public void map_without_wrapper() {
12  Map<Integer, String> mappings = new HashMap<>();
13  mappings.put(1, "one");
14  mappings.put(2, "two");
15 
16  String xml = new SerializationSvc().toXML(mappings);
17  String json = new SerializationSvc().toJSON(mappings);
18 
19 
20  System.out.println(xml);
21  System.out.println(json);
22 
23  }
24 
25  @org.junit.Test
26  public void map_within_wrapper() {
27  MapWrapper wrapper = new MapWrapper();
28  Map<Integer, String> mappings = new HashMap<>();
29  mappings.put(1, "one");
30  mappings.put(2, "two");
31  wrapper.mappings = mappings;
32 
33  String xml = new SerializationSvc().toXML(wrapper);
34  String json = new SerializationSvc().toJSON(wrapper);
35 
36 
37  System.out.println(xml);
38  System.out.println(json);
39 
40  }
41 }
Xstream and Jettison based serialization Jackson is arguably the standard Java Library for processing...