0

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.

Community
  • 1
  • 1
callMeJava
  • 61
  • 1
  • 2
  • 12
  • Isn't the problem actually this `type="tns:ArrayOfString"`? The `ArrayOfString` is actually an object that it is creating for you from your complexType. – jbx Jan 20 '16 at 01:25
  • @jbx oh shoot, how did I not see that. I fixed the problem. I will post the solution below just in case. – callMeJava Jan 20 '16 at 02:07

2 Answers2

2

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"/>
jbx
  • 21,365
  • 18
  • 90
  • 144
0

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">

callMeJava
  • 61
  • 1
  • 2
  • 12