@XmlRootElement
public class Person {
@XmlElement
private String name;
@XmlElement
private int age;
}
JAXBContext jaxbContext = JAXBContext.newInstance(Person.class);
Marshaller marshaller = jaxbContext.createMarshaller();
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
marshaller.marshal(person, file);
Person person = (Person) unmarshaller.unmarshal(file);