[英]JAXB Unmarshaling - Lists
我目前正在开发一个用于自用的项目,在理解JAXB中的拆组过程时遇到了一些问题。
我有要保存到XML文件中的对象,该类对象是我如何进行编组。 现在,我需要在ArrayList中以unmarshaning方式加载的对象,以便在搜索某些东西时可以浏览所有对象。
我的代码如下所示:
@XmlRootElement()
public class Customer {
private int id;
private String name;
private String adress;
private String telephone;
private String firm = null;
// getters and Setters and Constructor
....
}
和我的JAXB Unmarshaller:
public void loadCustomers() throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
jaxbUnmarshaller.unmarshal(file);
}
为了将创建的对象插入列表,我应该在哪里设置? 可以做类似的事情吗
ArrayList customerList = jaxbUnmarshaller.unmarshal(file);
还是只有创建子类和超类的方法?
原来我的问题不是那么特别,我没有做正确的研究。
该链接为我做到了。 解释得很好,正是我需要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.