我正在编写一个RESTEasy客户端来连接RESTful服务 . RESTful服务如下所示:

@Path("locations")
public class LocationService {

    @POST
    @Path("/myObjects")
    @Produces({MediaType.APPLICATION_XML})
    @Consumes({MediaType.APPLICATION_XML})
    public List<MyObjects> CreateObjects( List<MyObjects> objList ) {
    ...
    }
}

MyObjects类包含正确的XML注释:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "my-objects")
public class MyObjects {
    ...
}

在我的客户端,我有一个我试图发布到服务的MyObjects列表,如下所示:

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;


public static voice main(String[] args){

    List<MyObjects> objectList = new ArrayList<>();
    objectList.add(...)

    ... 

    Client client = ClientBuilder.newClient();
    WebTarget target = client.target(RESTFUL_URL).path("locations/myObjects");
    Invocation.Builder builder = target.request(MediaType.APPLICATION_XML_TYPE);
    Entity< List<MyObjects> >  request = Entity.entity( objectList , MediaType.APPLICATION_XML_TYPE );

    Response resp = builder.post(request);

    if( Status.Family.Success == resp.getStatusInfo().getFamily() ) {
        ...
    }
}

builder.post(request) 行执行时,我得到以下异常:

javax.ws.rs.ProcessingException: could not find writer for content-type application/xml type: java.util.ArrayList
    at org.jboss.resteasy.core.interception.ClientWriterInterceptorContext.throwWriterNotFoundException(ClientWriterInterceptorContext.java:40)
    at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.getWriter(AbstractWriterInterceptorContext.java:138)
    at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:117)
    at org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.aroundWriteTo(GZIPEncodingInterceptor.java:100)
    at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:122)
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.writeRequestBody(ClientInvocation.java:341)
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.writeRequestBodyToOutputStream(ApacheHttpClient4Engine.java:558)
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.buildEntity(ApacheHttpClient4Engine.java:524)
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.loadHttpMethod(ApacheHttpClient4Engine.java:423)
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:281)
    ... 11 more

我不确定我在这里做错了什么 . 有没有人遇到过这类问题?非常感谢任何帮助!