user219882
user219882

Reputation: 15844

Using @XmlAnyElement in Java marshalling

I have this class

public class Header {

    @XmlAnyElement(lax = true)
    protected List<Object> any;

    // getters/setters omitted

}

How can I (in JAX-WS WebMethod) create an element ID in header that would look like this?

<Header>
    <ID>value</ID>
</Header>

Upvotes: 1

Views: 1537

Answers (1)

bdoughan
bdoughan

Reputation: 149007

You could have a class like the following and add an instance of it into the any property, or you could add an instance of org.w3c.dom.Element representing the ID element to the collection.

@XmlRootElement(name="ID")
@XmlAccessorType(XmlAccessType.FIELD)
public class ID {

    @XmlValue
    private String value;

}

Upvotes: 2

Related Questions