users@jax-ws.java.net

Re: xs:nill

From: Peter Hendry <peter.hendry_at_capeclear.com>
Date: Mon, 25 Jun 2007 21:42:44 +1200
The behaviour is correct. To send null for the actual reference to an array the element would have to be omitted. Consider a 2 element array with both elements being nil

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

So a one element array with a single null value would *have to* look like

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

An array which is a reference to null

    Aliases[] array = null;

can only be serialized as omission. Serializing it as xsi:nil="true" is incorrect and I would suggest should error if attempted when minOccurs="1".

Note that with this approach there is no way to differentiate between

  Aliases[] array = null;
  Aliases[] array = {};

Both would serialize by omission.

The way around this confusion is to use wrapped arrays. I'm guessing JAX-WS probably has an option to generate wrapped arrays. My preference would be to generate these by default as they remove any confusion over what nil="true" means

<sequence>
  <element name="aliases" nillable="true">
    <complexType>
      <sequence>
        <element name="alias" type="tns:criteriaAlias" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
      </sequence>
    </complexType>
  </element>
<sequence>

So

   Alias[] array = null;

becomes

  <aliases xsi:nil="true"/>

and

  Alias[] array = {};

becomes

  <aliases/>

and

  Alias[] array = { null };

becomes

  <aliases>
    <alias xsi:nil="true"/>
  </aliases>

So you can safely and unambiguously represent all 3 of

  Alias[] array = null;
  Alias[] array = {};
  Alias[] array = { null };

Pete



Dima Gutzeit wrote:
BTW,
 
The schema that is generated by JAXWS contains "nillable='true'", os it is ok for the client to send it ,,,
 
<xs:complexType name="searchCriteria">
<xs:sequence>
<xs:element name="aliases" type="tns:criteriaAlias" nillable="true" minOccurs="0" maxOccurs="unbounded"></xs:element>
<xs:element name="criterions" type="tns:criterion" nillable="true" minOccurs="0" maxOccurs="unbounded"></xs:element>
<xs:element name="numberOrItemsPerRequest" type="xs:int"></xs:element>
<xs:element name="orders" type="tns:order" nillable="true" minOccurs="0" maxOccurs="unbounded"></xs:element>
<xs:element name="requestNumber" type="xs:int"></xs:element>
<xs:element name="requireTotalRequestsCount" type="xs:boolean"></xs:element>
<xs:element name="subCriterias" type="tns:subCriteria" nillable="true" minOccurs="0" maxOccurs="unbounded"></xs:element>
<xs:element name="totalRequestCount" type="xs:int"></xs:element>
 
</xs:sequence>
</xs:complexType>
----- Original Message -----
From: Dima Gutzeit
To: users@jax-ws.dev.java.net
Sent: Monday, June 25, 2007 9:49 AM
Subject: xs:nill

Hi,
 
I see strange deserializing behavior in JAXWS 2.1.2.
Whenever it gets :
 
<aliases xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
 
It creates array with one null element. It is wrong :-(
 
Is there a way to configure this ?
 
Regards,
Dima Gutzeit.