@XmlRootElement
public class Person {
private String name;
private int age;
public static void main(String[] args) throws JAXBException {
Person person = new Person("John Doe", 30);
JAXBContext jaxbContext = JAXBContext.newInstance(Person.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.marshal(person, new File("person.xml"));
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Person unmarshalledPerson = (Person) unmarshaller.unmarshal(new File("person.xml"));
System.out.println(unmarshalledPerson.getName());
System.out.println(unmarshalledPerson.getAge());
}
}