I am new to using JAXB and I’m struggling with a problem right now. Perhaps you can help me.
I have the following code:
@XmlRootElement
public class Students implements Serializable{
private static final long serialVersionUID = 1L;
private List<Person> personList;
private int id;
// getters and setters for the attributes
}
and
@XmlRootElement
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
private int sex;
//getters and setters for the attributes
}
when I try to marshal Students this with JAXB, i only have the id-Element in the resulting string. I don’t have the list (persons). Where is the problem here?
There isn’t anything special you need to do to marshal
Listproperties. Just make sure one of the following is true:If you are using the JAXB reference implementation and have a getter for the
Listproperty but no setter, then you will need to annotate the getter with@XmlElementIf you don’t have a public accesssor, make sure you are using field access:
If you have a getter and setter for the
Listproperty then you don’t need to do anything:For More Information