users@jersey.java.net

Re: [Jersey] https://jersey.dev.java.net/issues/show_bug.cgi?id=18

From: coldserenity <muntyanu.roman_at_gmail.com>
Date: Thu, 22 Jan 2009 03:43:30 -0800 (PST)

Hello Paul,


Paul Sandoz wrote:
>
> I have just committed basic support in the trunk.
>
> You can return any type that is a instance of Collection<T> where T is
> a JAXB bean annotated with @XmlRootElement. The root element name is
> derived from the class name of T and is pluralized (assuming the name
> is an English word).
>

I'm using Jersey 1.0-ea.
This indeed works when Collection<T> is a return type of the WS method
E.g.
    @GET
    @Path("{start}/{count}")
    public Collection<SystemUserDTO> getUsers(@PathParam("start") Integer
start, @PathParam("count") Integer count);

however when I try to return a collection in the following manner
    @GET
    @Path("{start}/{count}")
    public Response getUsers(@PathParam("start") Integer start,
@PathParam("count") Integer count) {
      Collection<SystemUserDTO> usersList;
      ....
      return Response.ok().entity(usersList).build();
    }
I receive following exception:
  com.sun.jersey.api.client.UniformInterfaceException: Status: 500
        at com.sun.jersey.api.client.WebResource.handle(WebResource.java:468)
        at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:64)
        at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:356)
        ...
Is this a correct behavior or a bug with
Response.ok().entity(Collection<T>)? I couldn't find more on this than your
post.

Also on more question not directly related to Jersey. Which way of returning
results is more proper, the first one with explicit data type, or the second
one where everything is wrapped into response?

From what I see, first way is more strict, that is or you return a result or
you throw an exception. While the second approach gives you freedom in terms
of what to return.
What's your opinion?

Roman

-- 
View this message in context: http://n2.nabble.com/Re%3A-https%3A--jersey.dev.java.net-issues-show_bug.cgi-id%3D18-tp1082350p2197279.html
Sent from the Jersey mailing list archive at Nabble.com.