Java 将列表解组到LinkedList Jaxb
如何在解组列表时指定集合实现。对于一些实体列表,我更喜欢使用LinkedList,但jaxb为适当的元素创建了ArrayList。有没有最简单的方法来点集合Impl for ListJava 将列表解组到LinkedList Jaxb,java,jaxb,Java,Jaxb,如何在解组列表时指定集合实现。对于一些实体列表,我更喜欢使用LinkedList,但jaxb为适当的元素创建了ArrayList。有没有最简单的方法来点集合Impl for List 将列表属性初始化为链接列表: @XmlElement(name = "list-property") public List<ListProperty> listProperties = new LinkedList<ListProperty>(); @xmlement(name=“lis
将
列表属性
初始化为链接列表:
@XmlElement(name = "list-property")
public List<ListProperty> listProperties = new LinkedList<ListProperty>();
@xmlement(name=“list属性”)
public List listProperties=new LinkedList();
然后解组器将把它作为链表返回。Jaxb应该生成一个
list
格式的列表,这样您就可以使用任何实现。如果这不是您的情况,您可以添加一些jaxb生成arrayList的代码示例吗?我已经更新了POST,那么在创建每个对象时,空列表将始终被初始化。你的解决方案有效。但也许有一些优雅的解决方案可以避免这种行为?
<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);
}
}
@XmlElement(name = "list-property")
public List<ListProperty> listProperties = new LinkedList<ListProperty>();