How do I add array indices to the XML produced by JAXB?
Posted
by oconnor0
on Stack Overflow
See other posts from Stack Overflow
or by oconnor0
Published on 2010-06-17T22:08:06Z
Indexed on
2010/06/17
22:13 UTC
Read the original article
Hit count: 260
I have a Java bean ala
@XmlRootElement public class Bean {
@XmlElementWrapper(name = "ints") @XmlElement(name = "int")
int[] values;
// constructors, getters, setters, etc...
}
JAXB is producing XML like
<bean>
<ints>
<int>12</int>
<int>34</int>
<int>56</int>
</ints>
</bean>
I would like the array indices to be included on the <int>
tags as array position conveys important value. Preferably as attributes like
<bean>
<ints>
<int id='0'>12</int>
<int id='1'>34</int>
<int id='2'>56</int>
</ints>
</bean>
Is there a way to do this?
© Stack Overflow or respective owner