[ 
https://issues.apache.org/jira/browse/CXF-3111?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Daniel Kulp resolved CXF-3111.
------------------------------

       Resolution: Not A Problem
    Fix Version/s: Invalid


I'm marking this invalid as it's working per JAXB spec.   By default, the array 
would be mapped to 
{code:xml}
<element name="intArray" minOccurs="0" maxOccurs="unbounded" type="xsd:int"/>
{code}
Thus, if you want an empty/null array, you would just not send an intArray 
element on the wire.   Each intArray element on the wire is an element for the 
array.  With schemavalidation turned  off (the default), it parsed the elements 
value (emtpy/null string in your case) to an int which would be 0.   Turning 
schema validation on would throw an exception.

If you wanted a "wrapper" element, you would need to generate wrapper types, 
configure them in, modify them to add an @XmlElementWrapper annotation, etc...

> Empty SOAP element as argument to int[] parameter results in single-element 
> of 0 int array
> ------------------------------------------------------------------------------------------
>
>                 Key: CXF-3111
>                 URL: https://issues.apache.org/jira/browse/CXF-3111
>             Project: CXF
>          Issue Type: Bug
>          Components: JAXB Databinding
>    Affects Versions: 2.2.11
>         Environment: Ubuntu Maverick 64-bit, Java SE 1.6.0_20, Eclipse 3.6 
> Web Services Explorer, Tomcat 6.0.26
>            Reporter: Scott Van Wart
>             Fix For: Invalid
>
>
> When I call a CXF-hosted web service that accepts an int array as a 
> parameter, and I give it an empty element as that parameter in the SOAP 
> message, I end up with an int array with a single element of '0'.
> The SEI:
> {noformat}
> @WebService( name="intTest", targetNamespace="http://int.test.example.org"; )
> public interface IntTest
> {
>   @WebMethod public String doTest(
>     @WebParam( name="intArray" ) int[] intArray );
> }
> {noformat}
> Inbound SOAP message:
> {noformat}
> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; 
> xmlns:q0="http://int.test.example.org";
>     xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
>   <soapenv:Header/>
>   <soapenv:Body>
>     <q0:doTest>
>       <intArray/>
>     </q0:doTest>
>   </soapenv:Body>
> </soapenv:Envelope>
> {noformat}
> My implementation:
> {noformat}
> @WebService( endpointInterface="IntTest" )
> public class IntTestImpl implements IntTest {
>   public String doTest( int[] intArray ) {
>     StringBuilder s = new StringBuilder( "[" );
>     for ( int n = 0; n < intArray.length; ++n ) {
>       if ( n > 0 ) {
>         s.append( ',' );
>       }
>       s.append( Integer.toString( intArray[n] ) );
>     }
>     s.append( ']' );
>     return s.toString();
>   }
> }
> {noformat}
> Outbound SOAP message:
> {noformat}
> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";>
>   <soap:Body>
>     <ns2:doTestResponse xmlns:ns2="http://int.test.example.org";>
>       <return>[0]</return>
>     </ns2:doTestResponse>
>   </soap:Body>
> </soap:Envelope>
> {noformat}
> Personally I would have expected either null or, more logically, an empty 
> array to be passed to my implementing method.  By giving a sentinal value in 
> the array, it forces callers to have separate checks and avoid sending the 
> parameter if it has no value.  I wasn't sure whether this was a data binding 
> issue, something with CXF, or something about a specification I don't 
> understand, but I thought I'd try under JAXB binding.
> Thanks.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to