public void marshalObjectToXml(Person person, File output) {
try {
JAXBContext context = JAXBContext.newInstance(Person.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(person, output);
} catch (JAXBException e) {
e.printStackTrace();
}
}
public Person unmarshalXmlToObject(File input) {
try {
JAXBContext context = JAXBContext.newInstance(Person.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
return (Person) unmarshaller.unmarshal(input);
} catch (JAXBException e) {
e.printStackTrace();
return null;
}
}
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory