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? –
我已更新文章 –