You cannot use both @Text and @ElementListUnion of type String.class. Once I tried without @Text Simple Framework was much happier.
Mixed value and element with SimpleXML/Simple framework
-
23-06-2022 - |
Question
I have the following XML to parse (this is only part of the National Digital Forecast Database):
<production-center>
Meteorological Development Laboratory
<sub-center>Product Generation Branch</sub-center>
</production-center>
and I created the following class to use this:
@Element
public class ProductionCenter {
@Element(name = "sub-center")
public String subCenter;
@Text(required = false)
public String value;
}
However this does not work, because it's expecting only Text as the value, and there's an additional element there.
How can I get Simple Framework to be happy with this XML structure? I cannot change the XML, so making it more 'valid' is not an option.
-- I've tried the following too --
@Element
public class ProductionCenter {
@Text
@ElementListUnion({
@ElementList(entry="sub-center", type=String.class, inline=true),
})
public List<Object> values;
}
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow