You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Daniel Lipofsky <Da...@bricsnet.com> on 2008/02/26 00:24:23 UTC

best practices for Map and List in webservices

I have got some WebServices that basically take and return
Map<String,String> and List<String>.  I am wondering what is
considered the best way to do this, especially for interoperability
with both Java and .NET.  I don't have to use the Java collections
(although it sure is convenient).  Previously we used WebMethods Glue
which provided this for us, but I understand it was not great for
interoperability.

Thanks,
Dan

Re: best practices for Map and List in webservices

Posted by Benson Margulies <bi...@gmail.com>.
Maps are hard. JAXB barely support them, with a ton of snails, in 2.1. I
would personally recommend specifying a vector or list of pairs instead.

On Mon, Feb 25, 2008 at 6:24 PM, Daniel Lipofsky <
Daniel.Lipofsky@bricsnet.com> wrote:

> I have got some WebServices that basically take and return
> Map<String,String> and List<String>.  I am wondering what is
> considered the best way to do this, especially for interoperability
> with both Java and .NET.  I don't have to use the Java collections
> (although it sure is convenient).  Previously we used WebMethods Glue
> which provided this for us, but I understand it was not great for
> interoperability.
>
> Thanks,
> Dan
>

Re: best practices for Map and List in webservices

Posted by Daniel Kulp <dk...@apache.org>.

Lists should be completely usable with JAX-WS/JAXB (and Aegis as well) as 
long as you properly type the exact instance.  Example:

class MyBean {
   List<Foo> myList;
}

and don't try things like:

class MyBean<T> {
   List<T> myList;
} 

of 

class MyBean{
   List myList;
}

The last one CAN be made to work, but it may require some extra 
configuration to get the classes that you put into the list added to the 
jaxb context and stuff.   It also maps in to the schema as just an 
xsd:anyType, which can sometimes cause issues with some stacks.

Maps, on the other hand, are really hard to get working (with JAXB).   
You need to write special JavaTypeAdapters things to convert the maps 
to/from special pair beans, and stuff.   It basically requires quite a 
bit more work at this point.

Dan


On Monday 25 February 2008, Daniel Lipofsky wrote:
> I have got some WebServices that basically take and return
> Map<String,String> and List<String>.  I am wondering what is
> considered the best way to do this, especially for interoperability
> with both Java and .NET.  I don't have to use the Java collections
> (although it sure is convenient).  Previously we used WebMethods Glue
> which provided this for us, but I understand it was not great for
> interoperability.
>
> Thanks,
> Dan



-- 
J. Daniel Kulp
Principal Engineer, IONA
dkulp@apache.org
http://www.dankulp.com/blog