On Wednesday 03 October 2007, Kaleb Walton wrote:
> Do you know why that is the case? Maybe because since it's empty they
> figured there shouldn't be any wasted space in the XML doc?

It's probably a combination of:
1) Less bandwidth used on the wire

2) Mappings in other toolkits - toolkits like JAXB and .NET and JAX-RPC, 
etc.... usually map the "wrapper" type to an object that holds the list 
or array, but would map the current thing directly to an array or list.   
That simplifies the programming model.

2) Simplified schema.   You don't end up with a wrapper type for every 
list.   Imaging, for example, a method that takes 3 lists.   With 
wrapped/doc/lit, you currently end up with something like:
<element name="doFooRequest">
 <complexType>
  <sequence>
    <element name="foo" type="string" 
           minOccurs="0" maxOccurs="unbounded" nillable="true"/> 
    <element name="bar" type="long" 
           minOccurs="0" maxOccurs="unbounded" nillable="true"/> 
    <element name="snarf" type="float" 
           minOccurs="0" maxOccurs="unbounded" nillable="true"/> 
</sequence>
<complexType>
</element>

If you had to wrap all the lists up, it would be something like:
<complexType name="StringList">
  <sequence>
    <element name="item" type="string" 
           minOccurs="0" maxOccurs="unbounded" nillable="true"/> 
  </sequence>
<complexType>
<complexType name="IntList">
  <sequence>
    <element name="item" type="int" 
           minOccurs="0" maxOccurs="unbounded" nillable="true"/> 
  </sequence>
<complexType>
<complexType name="FloatList">
  <sequence>
    <element name="item" type="float" 
           minOccurs="0" maxOccurs="unbounded" nillable="true"/> 
  </sequence>
<complexType>
<element name="doFooRequest">
 <complexType>
  <sequence>
    <element name="foo" type="tns:StringList"/> 
    <element name="bar" type="tns:IntList"/> 
    <element name="snarf" type="tns:FloatList"/> 
</sequence>
<complexType>
</element>

Basically, you end up with a significantly larger schema.

Dan

>
> It's a pain for my consumers to have to check for the existence of a
> variable before trying to parse it out - not the end of the world but
> it adds somewhat redundant code.
>
>
> Regards,
> Kaleb
>
> |------------>
> | From:      |
> |------------>
> |
>   >-------------------------------------------------------------------
>   >-------------------------------------------------------------------
>   >------------|
>   >
>   |Daniel Kulp <[EMAIL PROTECTED]>                                     
>   |                                                                   
>   |            |
>   |
>   >-------------------------------------------------------------------
>   >-------------------------------------------------------------------
>   >------------|
> |
> |------------>
> | To:        |
> |------------>
> |
>   >-------------------------------------------------------------------
>   >-------------------------------------------------------------------
>   >------------|
>   >
>   |[email protected]                                      
>   |                                                                   
>   |            |
>   |
>   >-------------------------------------------------------------------
>   >-------------------------------------------------------------------
>   >------------|
> |
> |------------>
> | Cc:        |
> |------------>
> |
>   >-------------------------------------------------------------------
>   >-------------------------------------------------------------------
>   >------------|
>   >
>   |Kaleb Walton/Southfield/[EMAIL PROTECTED]                                  
>   |                                                                   
>   |            |
>   |
>   >-------------------------------------------------------------------
>   >-------------------------------------------------------------------
>   >------------|
> |
> |------------>
> | Date:      |
> |------------>
> |
>   >-------------------------------------------------------------------
>   >-------------------------------------------------------------------
>   >------------|
>   >
>   |10/02/2007 05:55 PM                                                
>   |                                                                   
>   |            |
>   |
>   >-------------------------------------------------------------------
>   >-------------------------------------------------------------------
>   >------------|
> |
> |------------>
> | Subject:   |
> |------------>
> |
>   >-------------------------------------------------------------------
>   >-------------------------------------------------------------------
>   >------------|
>   >
>   |Re: Empty List's not being marshaled?                              
>   |                                                                   
>   |            |
>   |
>   >-------------------------------------------------------------------
>   >-------------------------------------------------------------------
>   >------------|
>
> On Tuesday 02 October 2007, Kaleb Walton wrote:
> > I'm using the simple server configured via Spring. When an object
> > contains an empty list (not null) my response does not return it as
> > an empty list - it just excludes the property from the response. Is
> > there any way to force it to include the property?
>
> I'd probably have to see both the schema and the soap message.   Most
> likely, the answer is no without creating a holder bean to hold the
> list.
>
> For the most part, when we see something like List<String>, we just
> create:
> <element name="foo" type="string" maxOccurs="unbounded"
> nillable="true"/>
>
> In that case, if the list is empty (or even if the list is null),
> nothing representing the list will appear on the wire.   That is how
> the JAXB spec calls for it to be done.  If you want something always
> on the wire, the schema would have to be something like:
> <element name="fooList">
> <complexType>
> <sequence>
> <element name="foo" type="string" maxOccurs="unbounded"
> nillable="true"/> </sequence>
> <complexType>
> </element>
>
> and a "FooList" class would be created to hold the List<String>.
>
> --
> J. Daniel Kulp
> Principal Engineer
> IONA
> P: 781-902-8727    C: 508-380-7194
> [EMAIL PROTECTED]
> http://www.dankulp.com/blog



-- 
J. Daniel Kulp
Principal Engineer
IONA
P: 781-902-8727    C: 508-380-7194
[EMAIL PROTECTED]
http://www.dankulp.com/blog

Reply via email to