javaxmljaxbannotationsxml-binding

Java xml binding with JAXB: Marshaling content from a field into the root element


i have a class like this:

@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlRootElement(name="someClass")
public class SomeClass implements Serializable {
    [...]
    @XmlElement(name="field")
    public String getSomeField() {
        return field;
    }
    [...]
}

The resulting XML after marshaling is, rightfully:

<someClass>
    <field>blablacontent</field>
</someClass>

I now want the content of "field" be the content of the someClass element directly, like this:

<someClass>
    blablacontent
</someClass>

I've looked around a lot what the annotations can do, i didn't find anything. Is this not possible ? Thanks very much for any advice !


Solution

  • If you have no other @XmlElement annotated properties in your class, you can use @XmlValue.