This is my XML file:
This is because, by default, Jaxb when serializes a pojo, looks for the annotations over the public members(getters or setters) of the properties. But, you are providing annotations on fields. so, either change and set the annotations on setters or getters of properties, or sets the XmlAccessortype to field.
Option 1::
@XmlRootElement(name = "fields")
@XmlAccessorType(XmlAccessType.FIELD)
public class Fields {
@XmlElement(name = "field")
List fields = new ArrayList();
//getter, setter
}
@XmlAccessorType(XmlAccessType.FIELD)
public class Field {
@XmlAttribute(name = "mappedField")
String mappedField;
//getter,setter
}
Option 2::
@XmlRootElement(name = "fields")
public class Fields {
List fields = new ArrayList();
@XmlElement(name = "field")
public List getFields() {
}
//setter
}
@XmlAccessorType(XmlAccessType.FIELD)
public class Field {
String mappedField;
@XmlAttribute(name = "mappedField")
public String getMappedField() {
}
//setter
}
For more detail and depth, check the following JDK documentation http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/annotation/XmlAccessorType.html