@XmlRootElement
public class Person {
private String name;
private int age;
}
public class Main {
public static void main(String[] args) throws JAXBException {
Person person = new Person();
person.setAge(25);
JAXBContext context = JAXBContext.newInstance(Person.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter writer = new StringWriter();
marshaller.marshal(person, writer);
String xml = writer.toString();
System.out.println(xml);
}
}