簡體   English   中英

cxf / jaxb復雜類型

[英]cxf / jaxb complex types

我使用CXF從WSDL生成類,但是我不知道如何訪問以下字段:

<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>

結果類為:

@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;
    }

}

如果嘗試使用以下方法獲取數據,則我有一個對象類型

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

那么如何讀取對象中的數據呢?

謝謝

您的復雜類型“ text-with-layout-type”包含一個“ any”標簽。 這意味着JAXB需要能夠處理任何類型的數據,因此將數據鍵入為Object。

照原樣使用代碼,您將需要利用getClass()或instanceof來確定類型。 如果您希望通過某種方式查看此屬性,請通過問題的更新告知我,我們可以討論替代映射以啟用該行為。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM