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