title: Not able to send an ArrayList in a POST request to the REST server using Java
body: <p>I am a newbie to the Java REST services, rather this whole Java client-server thing. I'm trying to implement the basic client server design.  </p>
  
  <p>From client side I am trying to POST an <code>ArrayList</code> of objects of a particular class (POJO). Following is my client side code:</p>
  
  <pre><code>public class TestClient1 {
  
      private static final String webServiceURI = "http://localhost:8080/IadssitHPCServer";
      private static URI serviceURI;
      private static WebTarget webTarget;
      private static ArrayList&lt;ImageInput&gt; imageList;
  
      public static void main(String[] args) {
  
          ClientConfig clientConfig = new ClientConfig();
          Client client   = ClientBuilder.newClient(clientConfig);
          serviceURI  = UriBuilder.fromUri(webServiceURI).build();
          webTarget   = client.target(serviceURI);
          webTarget   = webTarget.path("clientserver").path("restservice").path("analyze");
  
          imageList = new ArrayList&lt;ImageInput&gt;();
  
          /*
            Code to add objects in the Arraylist
          */  
  
          Session session= webTarget.request().accept(MediaType.APPLICATION_XML).
                  post(Entity.entity(imageList, MediaType.APPLICATION_XML), Session .class);
      }
  }
  </code></pre>
  
  <p><code>ImageInput</code> (POJO) class:</p>
  
  <pre><code>@XmlRootElement
  public class ImageInput implements Serializable {
  
      private String imageName;
      private String imageDirPath;
  
      public String getImageName() {
          return imageName;
      }
      public void setImageName(String imageName) {
          this.imageName = imageName;
      }
      public String getImageDirPath() {
          return imageDirPath;
      }
      public void setImageDirPath(String imageDirPath) {
          this.imageDirPath = imageDirPath;
      }
  }
  </code></pre>
  
  <p>At server:</p>
  
  <pre><code>@Path( "/hpcservice" )
  @Consumes( MediaType.APPLICATION_XML )
  @Produces( MediaType.APPLICATION_XML )
  public class HpcService {
  
      @POST
      @Path( "/analyze" )
      public Session startAnalysing(ArrayList&lt;ImageInput&gt; clientInput){
          System.out.println( "Started Analyzing..." );
          return session;
      }
  }
  </code></pre>
  
  <p>Server returns the object of the class <code>Session</code> which is again a POJO class.  </p>
  
  <p>When I execute the code it gives me following error at client side:</p>
  
  <pre><code>Oct 19, 2015 3:01:10 PM org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo
  SEVERE: MessageBodyWriter not found for media type=application/xml, type=class java.util.ArrayList, genericType=class java.util.ArrayList.
  org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/xml, type=class java.util.ArrayList, genericType=class java.util.ArrayList.
      at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:247)
      at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
      at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1154)
      at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:503)
      at org.glassfish.jersey.client.HttpUrlConnector._apply(HttpUrlConnector.java:315)
      at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:227)
      at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:246)
      at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:683)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
      at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:424)
      at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:679)
      at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:435)
      at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:338)
      at com.TestClient1.main(TestClient1.java:61)
  </code></pre>
  
  <p>I think may be I am doing something wrong with the type of request I am sending and receiving. How does this <code>MediaType.APPLICATION_..</code> affect/vary with the different data structure I am sending?</p>
  
  <p>I know I am asking a very basic level questions here, but whatever online solutions I find even on Stack Overflow, I am getting more confused.  </p>