@XmlRootElement
public class Person {
@XmlElement
private String name;
@XmlElement
private int age;
}
public class JAXBExample {
public static void main(String[] args) {
try {
Person person = new Person();
person.setName("John");
person.setAge(30);
JAXBContext jaxbContext = JAXBContext.newInstance(Person.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(person, System.out);
} catch (JAXBException e) {
e.printStackTrace();
}
}
}