Alexander Kleinhans
Alexander Kleinhans

Reputation: 6258

JAXB self closing tag marshaling

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

Answers (1)

Ori Marko
Ori Marko

Reputation: 58862

You need to add a fixed (static) value

@XmlAttribute(name="data")
private final static String DATA = "whatever";

Upvotes: 1

Related Questions