I am currently working on a project for selfuse and got some problems with understanding the unmarshaling process in JAXB.
I've got my Objects, which i want to save into an XML File, what i do with marshalling. Now i need the Objects, which i load with unmarshaling, in an ArrayList, so i can look through all of them, while i am searching for certain things.
My code looks like this:
@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
....
}
And My JAXB Unmarshaller:
public void loadCustomers() throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
jaxbUnmarshaller.unmarshal(file);
}
Where do i set in, in Order to insert the created Objects into a list? Would it be possible to do something like
ArrayList customerList = jaxbUnmarshaller.unmarshal(file);
Or is there only the way with creating Sub and Superclasses?
Turns out my Question ain't that special and i didnt do my research properly.
This Link did it for me. It's explained very well and just what i needed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.