I want to serialize several instances of a class to an XML file using JAXB. One class is easy to serialize, but several are already a problem. Show how it can be done.
I used the code that I found here: JAXB-Demo .
Here is something like this:
ArrayList<Campaign> cam = new ArrayList<Campaign>(); cam.add(camp); // добавляем объект класс Campaign cam.add(camp2); // добавляем объект класс Campaign JAXBContext jaxbContext = JAXBContext.newInstance(Campaign.class); Marshaller marsh = jaxbContext.createMarshaller(); marsh.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marsh.marshal(cam,new FileOutputStream("ololo.xml"));