users@jersey.java.net

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

From: Brendan cheng <ccp999_at_hotmail.com>
Date: Mon, 25 Mar 2013 17:07:11 +0000

Hi Joe,
I got "Message writer not found for ArrayList<Animal>..."
When I try:
public JResponse<List<Animal>> getAnimals(){...
Brendan

From: jmocker_at_velti.com
To: users_at_jersey.java.net
Date: Mon, 25 Mar 2013 15:26:24 +0000
Subject: [Jersey] Re: How to use JResponse to return a list for interface







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










Joseph
Mocker | Senior Software Architect


t +1.650.566.7033 m +1.408.676.6625

e jmocker_at_velti.com @Mobclix



The leading global technology provider of

mobile marketing and advertising solutions









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)