[英]JAXB Does not Marshall as Expected
我的一個朋友讓我發這個問題:
編輯:他決定在他自己發布這個問題: JAXB Unmarshalls XML錯誤地我試圖刪除這個問題,但不能。
我正在嘗試編組一個名為MyContainer
的java類。 這個類擴展了另一個名為Container
類。 Container
有一個名為: protected List<ResourceReference<Component>> child
的變量
MyContainer
唯一的變量是它從Container
繼承的變量。 但是,當我將子列表作為XmlList
時,此List
將不會與JAXB編組。
它將作為XmlElement
編組,但這不是我想要顯示數據的方式。 當它作為XmlElement
編組時,它列出了List
中的屬性,但不是'heirarchially'它只列出了兩個元素,就好像它們是類的屬性一樣,而不是屬於子列表。
如何讓Jaxb正確編組List
(實例化為ArrayList)?
編輯:這是一個例子:這是我得到的:
<MyContainer name="Container Name">
<booleanVal>false</booleanVal>
<child id="Test Comp 1"/>
<child id="Test Comp 2"/>
</and>
這更符合我的期望:
<MyContainer name="Container Name">
<booleanVal>false</booleanVal>
<child> /// This would be the class variable of the extended Class, Container
<ResourceRef id="Entry 1">
<ResourceRef id="Entry 2">
</child>
</and>
我承認,我當前的結果可能來自於Container中的List,標有@XmlElement注釋。 但是,JAXB不會對其他任何東西進行編組。
使用@XmlElementWrapper
注釋您的列表。 見javadoc 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.