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

StackOverflow https://stackoverflow.com/questions/20725115

Вопрос

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 !

Это было полезно?

Решение

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top