Reputation: 6258
How do marshal a self-closing tag with JAXB (Java).
i.e. the class:
@XmlRootElement
public class Customer {
@XmlElement public String name;
@XmlElement public int age;
@XmlAttribute public int id;
}
Would marshal to:
<customer id="3">
<name>TEST</name>
<age>100</age>
</customer>
If I wanted something like an element <something data='whatever'/>
inside Customer, is there an annotation for this?
EDIT:
To clarify, what I would like is:
<customer id="3">
<name>TEST</name>
<age>100</age>
<something data='whatever'/>
</customer>
Upvotes: 0
Views: 966
Reputation: 58862
You need to add a fixed (static) value
@XmlAttribute(name="data")
private final static String DATA = "whatever";
Upvotes: 1