我有一个看起来像这样的XML文件
<coordinate>
<url>http://some-url</url>
<properties>
<property type="integer">key1=12345</property>
<property visibility="private" type="string">key2=value2</property>
</properties>
</coordinate>
我希望生成一个如下所示的Object结构:
class Coordinate
string url
List<Property> properties
class Property
string type
string visibility
Jaxb似乎需要在坐标元素和属性元素之间使用“属性”类型图层。有没有办法让它直接将属性添加到Coordinate对象中包含的列表?
答案 0 :(得分:1)
JAXB @XmlElementWrapper
注释可用于此场景,如下所示。
@XmlElementWrapper(name = "properties")
@XmlElement(name="property")
protected List<Property> propertyList = new ArrayList<Property>();