Search code examples
javaxml-serializationannotationsjaxbjaxb2

What is the Jaxb equivalent of a Text node value?


I am looking to convert a class that looks like this ...

public class Amenity {
   public String id;
   public String value;
}

into the following XML using JaxB annotations:

<amenity id="id-string-here">value-string-here</amenity>

Does anyone know what annotation to use on the value member variable to accomplish this? The closest I've gotten so far is:

@XmlRootElement
public class Amenity {
   @XmlAttribute
   public String id;
   @XmlElement
   public String value;
}

Unfortunately this approach doesn't allow me to specify that the value member variable should not be rendered as its own tag <value></value>.


Solution

  • I'm not 100% sure about this, but try to use an @XmlValue annotation instead of @XmlElement.