users@jersey.java.net

[Jersey] Re: How to return List<String> by GET?

From: Casper Bang <casper.bang_at_gmail.com>
Date: Tue, 15 Mar 2011 10:31:50 +0100

I've run into a similar "root cardinality problem", and had to resort to
introducing an artificial list wrapper just for the sake of XML
representation - which feels like a wrong thing to do. JAXB already has the
 @XmlElementWrapper annotation, but Jersey's JAXB message body writer does
not currently consider it if added to a resource:

    @GET
    @Path("/{persons}/")
    @Produces({"application/xml", "application/json",
"application/fastinfoset"})
    @XmlElementWrapper(name = "persons")
    public List<Person> getPersons(){
        ....
    }

It would be nice if the above could be done, seems like nice reuse of a JAXB
annotation and established mapping semantics.

/Casper


On Mon, Mar 14, 2011 at 10:58 AM, Pengfei Di <pengfei.di_at_match2blue.com>wrote:

> Hello group,
>
> I am trying to return a list of jaxb beans by a get request. However, I get
> some error message: A message body writer for Java class
> java.util.LinkedList is needed.
> I know that it is possible to use GenericEntity<List<String>> and return
> Reponse, or build a class to wrap the list. But I rather prefer the return
> type of List<String>.
>
> Is it possible to return List<String> at all? If yes, how can I write the
> message body writer for it?
>
> Thanks a lot in advance for any hints!
>
> Pengfei
>
>
>