Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB generates List<Jaxbelement> instead of fields

I'm trying to generate a class with the jaxb maven plugin from the following wsdl:

<xs:complexType name="ctpLeerling">
<xs:sequence>
  <xs:element minOccurs="0" name="achternaam" type="xs:string"/>
  <xs:element minOccurs="0" name="voorvoegsel" type="xs:string"/>
  <xs:element minOccurs="0" name="voorletters-1" type="xs:string"/>
  <xs:element minOccurs="0" name="roepnaam" type="xs:string"/>
  <xs:element minOccurs="0" name="roepnaam" type="xs:string"/>
  <xs:element name="geboortedatum" type="xs:date"/>
  <xs:element minOccurs="0" name="geslacht" type="xs:string"/>
  <xs:element name="jaargroep" type="tns:ctpVocabulaireGebondenVeld"/>
  <xs:element minOccurs="0" name="emailadres" type="xs:string"/>
  <xs:element minOccurs="0" name="fotourl" type="xs:string"/>
  <xs:element minOccurs="0" name="groep">
    <xs:complexType>
      <xs:sequence/>
      <xs:attribute name="key" type="xs:string"/>
    </xs:complexType>
  </xs:element>
  <xs:element minOccurs="0" name="subgroepen">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="groep">
          <xs:complexType>
            <xs:sequence/>
            <xs:attribute name="key" type="xs:string"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element minOccurs="0" name="mutatiedatum" type="xs:dateTime"/>
</xs:sequence>
<xs:attribute name="key" type="xs:string" use="required"/>

It gives me a class that has the following fields:

protected List<JAXBElement<?>> content;
@XmlAttribute(name = "key", required = true)
protected String key;

How can I generate fields of the wsdl properties instead of a list with JAXBElements? Thanks in advance!

Edit: I'm sorry I forgot to mention that I cannot edit the wsdl file!

like image 473
Rick Slot Avatar asked Jan 10 '23 14:01

Rick Slot


1 Answers

You are getting a List<JAXBElement> because you have two elements defined in your sequence with the same name.

<xs:element minOccurs="0" name="roepnaam" type="xs:string"/>
<xs:element minOccurs="0" name="roepnaam" type="xs:string"/>

The element would have been better defined as:

<xs:element minOccurs="0" maxOccurs="2" name="roepnaam" type="xs:string"/>

If you can't find a way to generate the class you want, you can always create one yourself and use an external binding file to have JAXB use if for that complex type during class generation.

<jxb:bindings schemaLocation="yourSchema.xsd">
    <jxb:bindings node="//xs:complexType[@name='ctpLeerling']">
        <jxb:class ref="com.example.YourOwnClass"/>
    </jxb:bindings>
</jxb:bindings>
like image 159
bdoughan Avatar answered Jan 21 '23 05:01

bdoughan