I've created a wrapper class like below (is this necessary? I tried serializing the treemap directly without making any wrapper class and it failed) following the answer provided in a similar thread.
@Root
public class Example {
@ElementMap(entry="property", value="value", attribute=true, inline=true)
private TreeMap<String, String> map;
public Example()
{
map = new TreeMap<String, String>() {
{
put("testing1", "a");
put("testing2", "b");
put("testing3", "c");
}
};
}
}
Then I try to serialize it with the code below:
Serializer serializer = new Persister();
Example example = new Example();
File result = new File("example.xml");
serializer.write(example, result);
The example.xml file is generated, but it is an empty file. Is it because Treemap is not supported by Simple XML? Am I doing something wrong?