text B inner text

Jaxb - umarshaling mixed xml element with value

I have the following xml element:

<FIELD1><COMP VAR="A">text B</COMP> inner text <COMP VAR="B">text B</COMP></FIELD1>

How to comment on this property using JAXB:

protected List<Object> compOrValue;

to have a list of COMP xml elemnts and String.

Is this possible with JAXB?

thank

+3
source share
1 answer

To achieve this, you can use a combination of @XmlAnyElement and @XmlMixed:

import java.util.List;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlMixed;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="FIELD1")
public class Root {

    protected List<Object> compOrValue;

    @XmlAnyElement
    @XmlMixed
    public List<Object> getCompOrValue() {
        return compOrValue;
    }

    public void setCompOrValue(List<Object> compOrValue) {
        this.compOrValue = compOrValue;
    }

}
+3
source

Source: https://habr.com/ru/post/1777210/


All Articles