views:

23

answers:

1

Hello,

I use CXF to generate the classes from WSDL but I don't know how to access the following field :

<s:complexType name="text-with-layout-type" mixed="true">
<s:sequence>
<s:any minOccurs="0" maxOccurs="unbounded"/>
</s:sequence>
<s:attribute name="L" type="s:string"/>
</s:complexType>

The resulting class is :

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "text-with-layout-type", propOrder = {
    "content"
})
public class TextWithLayoutType {

    @XmlMixed
    @XmlAnyElement(lax = true)
    protected List<Object> content;
    @XmlAttribute(name = "L")
    protected String l;

    /**
     * Gets the value of the content property.
     * 
     * <p>
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a <CODE>set</CODE> method for the content property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getContent().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link Object }
     * {@link String }
     * 
     * 
     */
    public List<Object> getContent() {
        if (content == null) {
            content = new ArrayList<Object>();
        }
        return this.content;
    }

    /**
     * Gets the value of the l property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getL() {
        return l;
    }

    /**
     * Sets the value of the l property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setL(String value) {
        this.l = value;
    }

}

I have an Object type if I try to get data using

.getTextWithLayout().get(0).getContent()

So how can read the data in the Object ?

Thanks

A: 

Your complex type "text-with-layout-type" contains an "any" tag. This means that JAXB needs to be able to handle any type of data, therefore it typed the data as Object.

With the code as is you will need to leverage getClass() or instanceof to figure out the type. If you have a particular way you want this property to look then let me know through an update to the question and we can discuss alternative mappings to enable that behaviour.

Blaise Doughan
Thanks for your answer.The content expected is HTML/XHTML.
BenoitD