cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Kulp <>
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"/>

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">
           <element name="item" minOccurs="0" maxOccurs="unbounded"/>

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.


> --
> View this message in context:
> sues-in-JAX-B-over-REST-tp5709155p5709207.html Sent from the cxf-user
> mailing list archive at
Daniel Kulp -
Talend Community Coder -

View raw message