0
如何在解组列表时指定集合实现。对于一些我喜欢使用LinkedList的实体列表,但jaxb为适当的元素创建了ArrayList。列表>是否有最简单的方法来指向集合Impl?Unmarshal list to LinkedList Jaxb
@XmlRootElement(name = "column")
public class Column {
@XmlElement(name = "property")
public List<Property> properties;
@XmlElement(name = "list-property")
public List<ListProperty> listProperties;
}
。
<column>
<list-property name="a">...</list-property>
<list-property name="b">...</list-property>
<property name="width">10</property>
<property name="height">20</property>
</column>
。
public Column getObject(File file) {
try {
JAXBContext jc = JAXBContext.newInstance(Column.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
return (Column) unmarshaller.unmarshal(file);
} catch (JAXBException jex) {
throw new RuntimeException("Object parse was fail", jex);
}
}
Jaxb应该生成'List>'的形式列表,以便您可以使用任何实现。如果这不是你的情况,你可以添加一些代码示例,其中jaxb生成一个arrayList? –
我已更新文章 –