Java 无法使用JAX-B检索多个对象

Java 无法使用JAX-B检索多个对象,java,arraylist,jaxb,Java,Arraylist,Jaxb,我正在尝试将对象书店和对象列表添加到对象列表中。但我有以下例外: 例外情况: 15 Jul, 2013 4:47:07 PM com.sun.jersey.spi.container.ContainerResponse logException SEVERE: Mapped exception to response: 500 (Internal Server Error) javax.ws.rs.WebApplicationException: javax.xml.bind.MarshalEx

我正在尝试将对象书店和对象列表添加到对象列表中。但我有以下例外:

例外情况:

15 Jul, 2013 4:47:07 PM com.sun.jersey.spi.container.ContainerResponse logException
SEVERE: Mapped exception to response: 500 (Internal Server Error)
javax.ws.rs.WebApplicationException: javax.xml.bind.MarshalException
- with linked exception:
[javax.xml.bind.JAXBException: class java.util.ArrayList nor any of its super class is    known to this context.]
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:159)
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306)
这是我的班级:

但是,当我试图使用rest客户机获取输出时,我得到了错误。这是我的REST客户端:

公共类测试{
公共静态void main(字符串[]args){
ClientConfig=newdefaultclientconfig();
Client=Client.create(config);
WebResource服务=client.resource(getBaseURI());
ResponseList ResponseList=service.path(“rest”).path(“BookMain/get”).accept(MediaType.APPLICATION_XML).get(ResponseList.class);
书店bs=(书店)responseList.getList().get(0);
ArrayList lb=(ArrayList)responseList.getList().get(1);
}
请帮忙

编辑:

15 Jul, 2013 4:47:07 PM com.sun.jersey.spi.container.ContainerResponse logException
SEVERE: Mapped exception to response: 500 (Internal Server Error)
javax.ws.rs.WebApplicationException: javax.xml.bind.MarshalException
- with linked exception:
[javax.xml.bind.JAXBException: class java.util.ArrayList nor any of its super class is    known to this context.]
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:159)
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306)
这是我的回应者课程:

@XmlRootElement
@XMLSEEALSE({BookStore.class,Book.class})
公共类响应者{
私人名单;
公共列表getList(){
退货清单;
}
公共无效集合列表(列表){
this.list=列表;
}
}

似乎它在抱怨您的绑定。您有绑定文件和xsd吗?现在看来您应该使用
列表而不是
ArrayList
,但是没有绑定很难判断。ArrayList不能由JAXB自动编组,因为它不知道根目录的名称可以创建一个包含对象的arraylist的新类。@rAy我已经有了一个包含对象的arraylist的类,请查看edit@nattyddubbs我没有使用任何绑定文件或xsdYour错误来自服务器尝试封送到XML,而不是来自客户端尝试解组XML。您是否在服务器上的资源方法中返回响应列表?
returning books : ResponseList [list=[[Book [name=Book2, author=Author2], Book [name=Book3, author=Author3]]]]
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);
}
@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;
    }
}