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

I have an auto- cxf web service client for soap (using cxf ), and some elements are marked as optional.

If I do not set these elements, the request XML request to the web service has many 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"/> 

They are generated if wsdl contains:

 minOccurs="0" nillable="true" 

How to prevent the creation of these nil elements? Probably the web service itself does not need this information, because when I use soapUI and send clean xml requests that remove nil elements, the request still works.

My bind file:

 <jaxb:globalBindings generateElementProperty="false" /> 

So how can I prevent them from being created during submission?

+6
source share
1 answer

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

+1
source

Source: https://habr.com/ru/post/976056/


All Articles