I recently posted and answer at SO related to this:
It works, however, the issue is the deserialized multimap despite having no errors when deserializing, the conveted multimap seems to included a String key instead of an enum key internally thus the type in compile time would not be able to retrieve the value.
Here's the code:
@Test
public void testSerializeWithEnum() {
XStream xstream = new XStream(new JettisonMappedXmlDriver());
xstream.registerConverter(new MultimapConverter(xstream.getMapper()));
xstream.allowTypeHierarchy(Multimap.class);
xstream.addDefaultImplementation(ArrayListMultimap.class, Multimap.class);
Multimap<TestEnum, String> test = HashMultimap.create();
test.put(TestEnum.E1, "test");
String json = xstream.toXML(test);
System.out.println(json);
final Multimap<TestEnum, String> result = (Multimap<TestEnum, String>)xstream.fromXML(json);
Assert.assertEquals("test", result.get(TestEnum.E1).stream().findFirst());
}
public enum TestEnum {
E1
}
The result.get(TestEnum.E1) returns an empty array, debugging that point, shows result contains the ArrayList with the value "test" but with a key "E1"