Posts

Showing posts from July, 2016

JAXB: binding java with xml

JAXB allow binding between java objects and xml instance. Basically with JAXB you can do 'marshall' and 'unmarshall' operations. Marshall means the process of conversion from java objects to xml instance. With unmarshall means the opposite. Marshall example To start with marshalling we need at least our domain class. Suppose we have a city with many person and i want to have an xml file with a root element city wich contains more element of kind people. To do that we need one object of type city wich contains a collection of person objects City.java public class City { private List&ltPerson&gt list = new ArrayList&ltPerson&gt(); // get and set } Person.java public class Person { private String name; private String surname; private int age; // get and set } Now, since we want to use JAXB we need to annotate these classes so JAXB can bind them to the xml file. Basically th...