cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Kulp <dk...@apache.org>
Subject Re: Empty vs. Null collection serialization issues in JAX-B over REST
Date Wed, 06 Jun 2012 16:22:50 GMT
On Wednesday, June 06, 2012 08:18:27 AM icfantv wrote:
> So, after a ton of trial and error, I think we've found the root issue and
> I can't find it documented anywhere.
> 
> For fields that represent collections, it appears you need to add both the
> XmlElement("...") and XmlElementWrapper("...") attributes or empty
> collections will not be serialized and will result in the deserialized
> object version having a null value rather than empty.
> 
> Can anyone speak as to why this is the case?  Thanks.

Has to do with the generated XML and schema.   Without the wrapper, you 
would get something like:
<sequence name="...">
   <element name="item" minOccurs="0" maxOccurs="unbounded"/>
</sequence>

In that case, on the wire, you either have items written out or not.   There 
is no way on the wire to tell if, when there are no items, if it should be a 
null collection or empy collection.

With the wrapper, you get:
<sequence name="...">
   <element name="wrapper" minOccurs="0">
     <complexType>
        <sequence>
           <element name="item" minOccurs="0" maxOccurs="unbounded"/>
        </sequence>
     </complexType>
   </element>
</sequence>

Where the "wrapper" element represents the collection itself.  If no 
present, then the collection is null.  If it is present, the collection 
exists.  If there are no child items, then it is empty.

Dan




> 
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/Empty-vs-Null-collection-serialization-is
> sues-in-JAX-B-over-REST-tp5709155p5709207.html Sent from the cxf-user
> mailing list archive at Nabble.com.
-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Mime
View raw message