I made a change in the blogger configuration to ease the later work when blogging. It is possible that older entries are not correctly formatted.

Sunday, 1 September 2013

Tricky Generation with stupid error with List<JAXBElement> getContent()

I spent too much time trying to understand why my schema did not get generated correctly. So I want to describe here the problem.


I have wsdl with a schema element:

<xsd:complexType name="Person">
   <xsd:sequence>
     <xsd:element name="id" type="xsd:long" minOccurs="0" maxOccurs="1" />
     <xsd:element name="title" type="xsd:string" />
     <xsd:element name="firstName" minOccurs="1" maxOccurs="1" type="xsd:string" />
     <xsd:element name="firstName" minOccurs="1" maxOccurs="1" type="xsd:string" />
   </xsd:sequence maxOccurs="1">
</xsd:complexType>

I was wondering why the generated Element Person did not have the correct fields but instead

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Person", propOrder = {
"content"
})
public class Person
   @XmlElementRefs({
     @XmlElementRef(name = "title", namespace = "http://www.cgi.com/cgicv/", type = JAXBElement.class, required = false),
     @XmlElementRef(name = "id", namespace = "http://www.cgi.com/cgicv/", type = JAXBElement.class, required = false),
     @XmlElementRef(name = "birthDay", namespace = "http://www.cgi.com/cgicv/", type = JAXBElement.class, required = false),
     @XmlElementRef(name = "middleName", namespace = "http://www.cgi.com/cgicv/", type = JAXBElement.class, required = false),
     @XmlElementRef(name = "lastName", namespace = "http://www.cgi.com/cgicv/", type = JAXBElement.class, required = false),
     @XmlElementRef(name = "firstName", namespace = "http://www.cgi.com/cgicv/", type = JAXBElement.class, required = false)
   })
   protected List<JAXBElement<?>> content;




The problem comes from the mistaken firstName twice in the element definition. I spent a long time looking for the answer.
The javadoc contained some kind of unclear warning. As soon as the right info is written, the content is generated correctly:



@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Person", propOrder = {
   "id",
   "title",
   "firstName",
   "lastName",
   "middleName",
   "birthDay",
   "address"
})
public class Person {