I want to serialize an element that extends HashMap with Simple.
@Root(name = "settings")
@ElementMap(entry="element", key="id", attribute=true, required=true, empty=true)
public class Settings extends HashMap<String, Object> {
...
Whenever I serialize it, I get no errors, but I also get an empty file that looks like this:
<settings/>
Is there any way to do this without creating an inner object instead, and then having to delegate all of the methods to it?
I suppose the reason is, that Simple cant transform HashMaps.
If i run this code …
… i get the following exception:
org.simpleframework.xml.transform.TransformException: Transform of class java.util.HashMap not supportedNow, here is what i did to get your class serialized:
I’ve written a Converter which is used for transforming
Settings.The
Converterclass:The
Settingsclass:Testing:
File test.xml:
I guess there’s a better way (if not some more) to do this, but maybe this helps a bit.
Another point is,
@DefaultAnnotation doesn’t work here (Exception), possibly solving this may solve the whole problem