簡體   English   中英

JAXB解組-列表

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM