[英]How can i add an attribute to XML element for parent tag using JAXB annotations
如何在“事件”標簽中添加Lane的屬性(對於我寫過單獨類的每個子標簽)?
這是示例格式:
<TestRequest>
<Constraints>
<Currency>USD</Currency>
<ServiceFlags>
<ServiceFlag code = "" />
</ServiceFlags>
</Constraints>
<Events>
<Event type="Pickup">
<Location>
<Zip></Zip>
<Country></Country>
</Location>
</Event>
<Event type="Drop">
<Location>
<Zip></Zip>
<Country></Country>
</Location>
</Event>
</Events>
</TestRequest>
您可以使用XmlAdapter進行操作 。
首先,為ex創建XmlAdapter
。 EventAdapter
。
然后,添加注釋@XmlJavaTypeAdapter(EventAdapter.class)
,在其中定義@XmlAttribute(name = "type")
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.