Reputation: 40005
Suppose I have a JAXB element like this:
@XmlElement
private double value;
this will generate XML like this:
<value>3.14159</value>
Now, how do I modify my declaration (or customize JAXB marshalling) to generate XML like this instead:
<value type="double">3.14159</value>
The type
attribute will always have the same value, i.e. "double".
Thanks!
Upvotes: 2
Views: 440
Reputation: 403581
You need to a define a class that encapsulates the combination of the double and the string, and then annotate a static fixed value:
public class MyDouble {
@XmlValue
private double value;
@XmlAttribute(name="type")
private final static String TYPE = "double";
}
So then your code becomes:
@XmlElement
private MyDouble value;
Upvotes: 2