users@jersey.java.net

[Jersey] Re: How to use JResponse to return a list for interface

From: Joseph Mocker <jmocker_at_velti.com>
Date: Mon, 25 Mar 2013 15:26:24 +0000

What is happening? Are you getting an error? Are you getting a list of Dog objects instead of Animal? Need more information on what is going on.

  --joe


[Velti]<http://www.velti.com> Joseph Mocker | Senior Software Architect
t +1.650.566.7033 m +1.408.676.6625
e jmocker@velti.com @Mobclix<http://twitter.com/Mobclix>
[cid:sep111116c2ec9]
The leading global technology provider of
mobile marketing and advertising solutions

<http://mwc.velti.com/meet-us>

On Mar 25, 2013, at 2:31 AM, Brendan cheng wrote:

Hi,

I have a problem in return a collection of objects using their interface. for example, Animal is the interface and Dog is a class. where I can only do a list of dogs like so:

interface Animal{
}

class Dog implements Animal{
}

@GET
@Path("test")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public JResponse<List<Dog>> getDogs(){
...
List<Dog> dogs = new ArrayList<Dog>();
...
return JResponse.ok(dogs).build();
}


but I can't return a list of Animal, if:


Is it possible in JAXB?

Brendan




logo111110b7f6d
(image/gif attachment: logo111110b7f6d)

sep111116c2ec9
(image/gif attachment: sep111116c2ec9)