Search code examples
javajaxbjaxb2

Jaxb Element Annotation


How do i annotate my class to archive this xml structure:

<elementTag attribute="false">Testvalue</elementTag>

I tried to put elementTag into a seperate class, but then "Testvalue" is not inline as it is in my example.

Thanks and best regards, m


Solution

  • You can use the @XmlValue annotation.

    @XmlRootElement(name="elementTag")
    public class Root {
    
         @XmlAttribute
         public String getAttribute {
             return attribute;
         }
    
         @XmlValue
         public String getValue() {
             return value;
         }
    
    }