We would like to know how to bind Jaxb and unordered set with separate lists for every element.
/* ww w . ja v a2 s. c o m*/ 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.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; 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 @XmlAccessorType(XmlAccessType.FIELD) public static class Root { List<String> x; List<Integer> y; } }
input.xml
<?xml version="1.0" encoding="UTF-8"?> <root> <y>1</y> <x>A</x> <y>2</y> <x>B</x> <y>3</y> <x>C</x> </root>