I am getting XML from a REST service that looks like:
<entity>
<foo>
<count>1</count>
<date>1970-01-01</date>
<margin>78.67</margin>
</foo>
<bar>
<count>2</count>
<date>1450-09-17</date>
<margin>24.56</margin>
</bar>
<baz>
<count>11</count>
<date>1968-11-12</date>
<margin>98.76</margin>
</baz>
</entity>
And I'm parsing with a class Entity.java that has:
@XmlRootElement(name = "entity")
@XmlAccessorType(XmlAccessType.FIELD)
public class Entity implements Serializable {
@XmlElements({
@XmlElement(name="foo"),
@XmlElement(name="bar"),
@XmlElement(name="baz")
})
private List<EntityElement> entityElements;
....
With an EntityElement class like:
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class EntityElement implements Serializable {
@XmlElement(required = true)
private int count
@XmlElement(required = true)
private String date;
@XmlElement(required = false)
private long margin;
....
This all works exactly like I expect and I get a list of EntityElements. What I would like to do is add a name field and have it populated with the name of the element that was found (a foo, bar, or baz) but I'm not seeing any way to do this. Any help or suggestions would be appreciated.