Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent generation of xml 'nil' elements in soap webservice client?

I have an autogenerated soap webservice client (using cxf), and some elements are marked to be optional.

If I do not set these elements, the XML request send to the webservice has lot's of elements as follows:

<PayText xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<Name xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>

These are generated if the wsdl contains:

minOccurs="0" nillable="true"

How can I prevent the generation of these nil elements? Probably the webservice itself does not need this information, as when I use soapUI and the send the pure xml requests stripping out the nil elements, the request still works.

My binding file:

<jaxb:globalBindings generateElementProperty="false" />

So, how can I prevent them being generated during send?

like image 319
membersound Avatar asked Sep 30 '14 13:09

membersound


1 Answers

If an element is minOccurs="0" and nillable="true" then the generated property type will be a JAXBElement, something like JAXBElement<String>. When that property is null it will be excluded from the marshalled XML (null corresponds to minOccurs="0"). To get xsi:nil="true" you need to have an instance of JAXBElement with nil set to true.

like image 123
bdoughan Avatar answered Oct 11 '22 14:10

bdoughan