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

171 views Asked by At

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 !

1

There are 1 answers

3
Sotirios Delimanolis On BEST ANSWER

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