You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by greenstar <jn...@gmail.com> on 2008/06/04 20:53:49 UTC

Marshalling arrays:

Consider this example client:

@WebServicetargetNamespace="http://foobar.com")
public interface Test {

    @WebMethod(operationName = "x")
    public String x(
            @WebParam(name = "values") String[] values);    
}

Using JaxWsProxyFactoryBean, the array argument gets marshalled to:

<values>1</values>
<values>2</values>
<values>3</values>

I would like to marshal it like this:

<values>
  <value>1</value>
  <value>2</value>
  <value>3</value>
</values>

This seems like this would make it much easier to determine between an empty
array and "not provided" (ie: null) at the other end.  When I send an empty
array, it gets unmarshalled to a null at the other end because it can't tell
the difference.

I can make a wrapper object and things work fine, but shouldn't the standard
simple case using arrays work in a safer way?  What am I missing?

Thanks
-- 
View this message in context: http://www.nabble.com/Marshalling-arrays%3A-tp17653605p17653605.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Marshalling arrays:

Posted by Daniel Kulp <dk...@apache.org>.
This is completely per JAX-WS/JAXB spec.   I was hoping we could do  
something like adding the XmlElementWrapper annotation onto the  
parameter like we can for the XmlMimeType and XmlList annotations, but  
XmlElementWrapper has:
@Retention(RUNTIME) @Target({FIELD, METHOD})
so there isn't really anything we can do about it.  :-(     Creating  
the wrapper objects is about the only option.


Dan



On Jun 4, 2008, at 2:53 PM, greenstar wrote:

>
> Consider this example client:
>
> @WebServicetargetNamespace="http://foobar.com")
> public interface Test {
>
>    @WebMethod(operationName = "x")
>    public String x(
>            @WebParam(name = "values") String[] values);
> }
>
> Using JaxWsProxyFactoryBean, the array argument gets marshalled to:
>
> <values>1</values>
> <values>2</values>
> <values>3</values>
>
> I would like to marshal it like this:
>
> <values>
>  <value>1</value>
>  <value>2</value>
>  <value>3</value>
> </values>
>
> This seems like this would make it much easier to determine between  
> an empty
> array and "not provided" (ie: null) at the other end.  When I send  
> an empty
> array, it gets unmarshalled to a null at the other end because it  
> can't tell
> the difference.
>
> I can make a wrapper object and things work fine, but shouldn't the  
> standard
> simple case using arrays work in a safer way?  What am I missing?
>
> Thanks
> -- 
> View this message in context: http://www.nabble.com/Marshalling-arrays%3A-tp17653605p17653605.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

---
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog





Re: Marshalling arrays:

Posted by greenstar <jn...@gmail.com>.

ianroberts wrote:
> 
> greenstar wrote:
>> Consider this example client:
>> 
>> @WebServicetargetNamespace="http://foobar.com")
>> public interface Test {
>> 
>>     @WebMethod(operationName = "x")
>>     public String x(
>>             @WebParam(name = "values") String[] values);    
>> }
>> 
>> Using JaxWsProxyFactoryBean, the array argument gets marshalled to:
>> 
>> <values>1</values>
>> <values>2</values>
>> <values>3</values>
>> 
>> I would like to marshal it like this:
>> 
>> <values>
>>   <value>1</value>
>>   <value>2</value>
>>   <value>3</value>
>> </values>
>> 
>> This seems like this would make it much easier to determine between an
>> empty
>> array and "not provided" (ie: null) at the other end.  When I send an
>> empty
>> array, it gets unmarshalled to a null at the other end because it can't
>> tell
>> the difference.
>> 
>> I can make a wrapper object and things work fine, but shouldn't the
>> standard
>> simple case using arrays work in a safer way?  What am I missing?
> 
> I think this is what the @XmlElementWrapper JAXB annotation does, but to 
> use that you'd have to create the request wrapper bean explicitly 
> (either manually or with the wsgen tool from Java 6 or Metro) and then 
> annotate the values property in that with @XmlElementWrapper.
> 
> I guess the alternative would be to create your wrapper object and then 
> register a type adapter to use your wrapper object in place of String[].
> 
> Neither option is particularly elegant :-(
> 

Yeah, if I make a wrapper object I have many more options.  However I am
simply questioning the "default" behavior of Array types not being wrapped
hence making it difficult to distinguish between empty and null (not
provided).  I was hoping that maybe I was missing something and there was a
way I could control this  without making a wrapper object.

-- 
View this message in context: http://www.nabble.com/Marshalling-arrays%3A-tp17653605p17658507.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Marshalling arrays:

Posted by Ian Roberts <i....@dcs.shef.ac.uk>.
greenstar wrote:
> Consider this example client:
> 
> @WebServicetargetNamespace="http://foobar.com")
> public interface Test {
> 
>     @WebMethod(operationName = "x")
>     public String x(
>             @WebParam(name = "values") String[] values);    
> }
> 
> Using JaxWsProxyFactoryBean, the array argument gets marshalled to:
> 
> <values>1</values>
> <values>2</values>
> <values>3</values>
> 
> I would like to marshal it like this:
> 
> <values>
>   <value>1</value>
>   <value>2</value>
>   <value>3</value>
> </values>
> 
> This seems like this would make it much easier to determine between an empty
> array and "not provided" (ie: null) at the other end.  When I send an empty
> array, it gets unmarshalled to a null at the other end because it can't tell
> the difference.
> 
> I can make a wrapper object and things work fine, but shouldn't the standard
> simple case using arrays work in a safer way?  What am I missing?

I think this is what the @XmlElementWrapper JAXB annotation does, but to 
use that you'd have to create the request wrapper bean explicitly 
(either manually or with the wsgen tool from Java 6 or Metro) and then 
annotate the values property in that with @XmlElementWrapper.

I guess the alternative would be to create your wrapper object and then 
register a type adapter to use your wrapper object in place of String[].

Neither option is particularly elegant :-(

Ian

-- 
Ian Roberts               | Department of Computer Science
i.roberts@dcs.shef.ac.uk  | University of Sheffield, UK