callMeJava
callMeJava

Reputation: 71

cxf wsdl2java generating ArrayOf<Type> instead of Type[]

I am using cxf wsdl2java commandline command in order to generate the client (java files). My xsd looks something like this -

<xs:complexType name="ArrayOfString">
    <xs:sequence>
        <xs:element maxOccurs="unbounded" minOccurs="0" name="string" type="xs:string"/>
    </xs:sequence>
</xs:complexType>   
<xs:element name="ConfirmSMSResults">
<xs:complexType>
    <xs:sequence>
    <xs:element maxOccurs="1" minOccurs="1" name="sessionId" type="xs:string"/>
    <xs:element maxOccurs="1" minOccurs="1" name="smsIds" type="tns:ArrayOfString"/>
    </xs:sequence>
</xs:complexType>   

The generated java file ConfirmSMSResults.java has something like this

@XmlElement(required = true) protected ArrayOfString smsIds;

where it should be protected String[] smsIds;

I had a similar problem with the date data type defined in the xsd file, which got converted to XMLGregorianCalendar. However, I solved it by using an external xjb file and defining the binding there. It could be found here. I can't seem to find something similar for my issue with the Array.

Thank you in advance.

Upvotes: 0

Views: 2206

Answers (2)

callMeJava
callMeJava

Reputation: 71

Okay, so it seems like I missed something. The type property refers to ArrayofString object, instead it should be xs:string. There seems to be no need of ArrayOfStrings object. Also, maxOccurs should be equal to unbounded. End result -

<xs:element name="ConfirmSMSResults">
    <xs:complexType>
        <xs:sequence>
            <xs:element maxOccurs="1" minOccurs="1" name="sessionId" type="xs:string"/>
            <xs:element maxOccurs="unbounded" minOccurs="1" name="smsIds" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

I also added collectionType="indexed"to my xjb file. So it looks something like this now <jaxb:globalBindings collectionType ="indexed">

Upvotes: 0

jbx
jbx

Reputation: 22158

You are saying that

it should be protected String[] smsIds

when in fact your XSD is not saying so.

Your XSD is saying that smsIDs is a complexType of type ArrayOfString which is defined at the top, and CXF will create a corresponding object ArrayOfString. Inside it there is an element called string which can occur multiple times, so probably you will find your array / list inside the ArrayOfString object it generates for your XSD.

If you want to remove that wrapper object, in your XSD you have to change this:

<xs:element maxOccurs="1" minOccurs="1" name="smsIds" type="tns:ArrayOfString"/>

to

<xs:element maxOccurs="unbounded" minOccurs="0" name="smsIds" type="xsd:string"/>

Upvotes: 2

Related Questions