users@jersey.java.net

RE: [Jersey] REST service returning Map collection

From: Gisella Saavedra <gisellas_at_yachay.net>
Date: Tue, 29 Sep 2009 22:34:09 -0700

Paul and Herak,

 

thanks much for the responses. I had tried writing an annotated class using
@ XmlJavaTypeAdapter but marshalling it failed. I am sure something was
wrong with my

annotations or implementation. I will review it again against your
suggestions/examples.

 

Gisella

 

 

From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
Sent: Monday, September 28, 2009 1:12 AM
To: users_at_jersey.dev.java.net
Subject: Re: [Jersey] REST service returning Map collection

 

 

On Sep 25, 2009, at 6:54 PM, Saavedra, Gisella wrote:.





 

Can somebody point me to an example or article, if it exists, containing a
code snippet returning a Map collection, something like

@GET

@Produces({"application/xml"})

public Map<String, String> getAttributes(.) { }

 

 

just receiving a Map object at the client side, or returning an object that
contains the Map?

No JSON.

 

I will appreciate it.

 

 

Herak provides some helpful examples.

 

If using the Jersey client API, but not using JAXB, then you will also
require a message body reader to de-serialize the XML to a map instance. For
such a case it will be easier to deal with a type that extends from
HashMap<String, String> so that you can avoid having to preserve the generic
types that would otherwise be erased.

 

So one could do:

 

 Client c = ...

 WebResource r = c.resource(...);

 MyMap mm = r.get(MyMap.class)

 

Paul.





Thanks.

 


Gisella Saavedra
Sr. Software Engineer
gsaavedra_at_zebra.com

 


<image001.gif>


1000 Broadway, Suite 150, Oakland, CA 94607 | T+1 510 267 5123 T Main+1
510 267 5000 F+1 510 267 5100 | http://www.zebra.com/zes