java - Unable to retrieve multiple objects using JAX-B -


i trying add object bookstore , list of objects of book list of objects. getting following exception:

exception:

15 jul, 2013 4:47:07 pm com.sun.jersey.spi.container.containerresponse logexception severe: mapped exception response: 500 (internal server error) javax.ws.rs.webapplicationexception: javax.xml.bind.marshalexception - linked exception: [javax.xml.bind.jaxbexception: class java.util.arraylist nor of super class    known context.] @ com.sun.jersey.core.provider.jaxb.abstractrootelementprovider.writeto(abstractrootelementprovider.java:159) @ com.sun.jersey.spi.container.containerresponse.write(containerresponse.java:306) 

this class:

@get @path("/get") @produces(mediatype.application_xml) public responselist addobjects() {      bookstore bookstore = new bookstore();     bookstore.setname("bookstore");     bookstore.setlocation("book palace");      book book1 = new book();     book1.setname("book2");     book1.setauthor("author2");      book book2 = new book();     book2.setname("book3");     book2.setauthor("author3");      arraylist<book> blist = new arraylist<book>();     blist.add(book1);     blist.add(book2);      arraylist<object> list = new arraylist<object>();     list.add(bookstore);     list.addall(blist);      responselist books = new responselist();     books.setlist(list);      system.out.println("returning books : " +books);     return books; } 

when printing books object (see second last line of program), getting following output:

returning books : responselist [list=[[book [name=book2, author=author2], book [name=book3, author=author3]]]] 

but, when trying take output using rest client getting error. rest client:

public class test {  public static void main(string[] args) {      clientconfig config = new defaultclientconfig();     client client = client.create(config);     webresource service = client.resource(getbaseuri());      responselist responselist = service.path("rest").path("bookmain/get").accept(mediatype.application_xml).get(responselist.class);     bookstore bs = (bookstore) responselist.getlist().get(0);     arraylist<book> lb = (arraylist<book>) responselist.getlist().get(1); } 

please ?

edit:

this responselist class:

@xmlrootelement @xmlseealso({bookstore.class,book.class}) public class responselist {      private list<object> list;      public list<object> getlist() {       return list;     }     public void setlist(list<object> list) {         this.list = list;     } } 


Comments