I am new to java (coming from c#.net background) and was trying the above example to marshal and unmarshal.
Following the link below
Marshalling a List of objects implementing a common interface, with JaxB
using the above technique as mentioned by Mr.Blaise Doughan, I was able to marshal the java objects to xml. But when i save this xml and try to unmarshal the xml back to java object i get the following on the console:
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2
counts of IllegalAnnotationExceptions
@javax.xml.bind.annotation.XmlElementRef annotation is found on two
places; one would be suffice. this problem is related to the following
location: at @javax.xml.bind.annotation.XmlElementRef(name=##default,
required=true, type=class
javax.xml.bind.annotation.XmlElementRef$DEFAULT, namespace=) at public
java.util.List Community.getPeople() at Community this problem is
related to the following location: at
@javax.xml.bind.annotation.XmlElementRef(name=##default,
required=true, type=class
javax.xml.bind.annotation.XmlElementRef$DEFAULT, namespace=) at public
void Community.setPeople(java.util.List) at Community ….
Note : I have created getters/setters for Class Boy and Class Girl for implementing unmarshalling.
It appears that you may have annotated both the getPeople and setPeople methods. JAXB (and other Java EE technologies) only require you annotate one.
For More Information