[英]How to use XStream for List<Object>?
我想根據JAXB和XStream進行映射。
這是代碼片段:
@XmlElements({
@XmlElement(name = "Success", type = SuccessType.class),
@XmlElement(name = "Warnings", type = WarningsType.class),
@XmlElement(name = "BagTypes", type = HashMap.class)
})
protected List<Object> successAndWarningsAndBagTypes;
如何使用XStream為List<Object>
進行類似的注釋映射?
或更簡單更好的辦法是將此List<Object>
划分為單獨的類實例?
更新 :
我必須根據以下xml文件映射此代碼段:
<EI_BaggageTypesRS Version="1.0" xmlns="http://www.opentravel.org/OTA/2003/05">
<Success/>
<BagTypes>
<ResponseBagType>
<code>AA</code>
<description>Golf Bag</description>
</ResponseBagType>
<ResponseBagType>
<code>BA</code>
<description>Skis</description>
</ResponseBagType>
<ResponseBagType>
<code>DA</code>
<description>Snow Board</description>
</ResponseBagType>
<ResponseBagType>
<code>CA</code>
<description>Fishing Gear</description>
</ResponseBagType>
<ResponseBagType>
<code>EA</code>
<description>Surf Board</description>
</ResponseBagType>
</BagTypes>
</EI_BaggageTypesRS>
有什么建議么?
假設代碼是從XML模式生成的,我將回答這個問題:
或更簡單更好的方法是將此List划分為單獨的類實例?
請看這個答案 。 拆分您的successAndWarningsAndBagTypes
一種方法是使用我的Simplify插件 。 您可以使用simplify:as-element-property
將一個@XmlElements
屬性拆分為多個@XmlElement
(末尾沒有s
)屬性。 例如,從此:
<xs:complexType name="typeWithElementsProperty">
<xs:choice maxOccurs="unbounded">
<xs:annotation>
<xs:appinfo>
<simplify:as-element-property/>
</xs:appinfo>
</xs:annotation>
<xs:element name="a" type="xs:string"/>
<xs:element name="b" type="xs:int"/>
</xs:choice>
</xs:complexType>
您會得到:
@XmlElement(name = "a", type = String.class)
protected List<String> a;
@XmlElement(name = "b", type = Integer.class)
protected List<Integer> b;
但是我不確定如何在wsimport
使用JAXB插件。 一定有可能,只是從未嘗試過。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.