2016-12-23 50 views
0

我目前正在研究自我使用的项目,并在理解JAXB中的解组过程时遇到了一些问题。JAXB Unmarshaling - 列表

我有我的对象,我想保存到一个XML文件,我用编组做什么。现在我需要在ArrayList中加载解组的对象,所以我可以查看所有这些对象,而我正在寻找某些东西。

我的代码如下所示:

@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); 

还是有只与创建Sub和超类的方法是什么?

回答

0

原来我的问题不是那么特别,我也没有做好我的研究。

Link为我做了。这很好的解释了我所需要的。