I am using Simple XML framework for deserialization on Android.
The xml that I need to deserialize is roughly like so:
<?xml version="1.0" encoding="UTF-8"?>
<elements type="array">
<element foo="x"/>
<element foo="y"/>
</elements>
In other words, it is an array right on the root level.
How to define a model class that I can deserialize it to?
I tried something as follows:
@Root (name = "elements")
public class Elements implements Serializable {
private static final long serialVersionUID = ...
@ElementArray (name = "element")
private List<Element> elements;
}
But it fails, since there is no type field to account for the type attribute in the xml.
Adding a type field (just for the sake of satisfying the deserializer) doesn't resolve the issue, generates another error instead: org.simpleframework.xml.core.InstantiationException: Type is not an array interface java.util.List for field 'elements' ...
What's the proper way of implementing the Elements class? Even though under time pressure, I'd like a clean solution, not some hackish workaround (that I'd probably come up with).