I am using SimpleXml.
The xml I am deserializing looks roughly like so:
<?xml version="1.0" encoding="UTF-8"?>
<test a="1" e="2" f="5"/>
That the attributes happen to be a, e and f is not known at runtime - could be q and z just as well.
The class definition:
@Root (strict = false)
public class Test {
@ElementMap (entry = "test", attribute = true)
public HashMap<String, Integer> map;
}
I expect Test.map to contain "a" -> 1, "b" -> 2 and "f" -> 5 after deserialization.
Instead, I keep on getting an exception: unnable to satisfy @org.simpleframework.xml.ElementMap ... on field 'map' ... for class Test ... (fluff removed - exception message doesn't contain any further clarification).
I tried to fiddle with various attributes of ElementMap (inlining, not inlining etc.), but to no success so far.
(It is actually the case that the values happen to be numeric, although that's circumstantial and I'd be fine going with string values to parse them on my own if that's necessary - not sure if it matters at all here though.)
What's the solution?
And if SimpleXml doesn't offer any out of the box, what's the suggested workaround?
No comments:
Post a Comment