import java.io.File;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
public class Main {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Root.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
File xml = new File("input.xml");
Root root = (Root) unmarshaller.unmarshal(xml);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(root, System.out);
}
@XmlRootElement
public static class Root {
private List list;
private List nestedList;
@XmlElement(name = "item")
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
@XmlElementWrapper(name = "items")
@XmlElement(name = "item")
public List getNestedList() {
return nestedList;
}
public void setNestedList(List nestedList) {
this.nestedList = nestedList;
}
}
}