title: REST client restTemplate can't get Collection of objects
body: <p>I use Spring restTemplate. I made a REST service and client as unit test in separated application. I have method that return List of users and method for user creating:</p>
  
  <pre><code>@GET
  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON,
          MediaType.TEXT_XML })
  @Path("/all")
  public Response getAllUsers() {
      List&lt;User&gt; list = dao.getAll();
      GenericEntity&lt;List&lt;User&gt;&gt; result = new GenericEntity&lt;List&lt;User&gt;&gt;(list) {
      };
      return Response.status(Status.OK).entity(result).build();
  }
  </code></pre>
  
  <p>If I request to show me all users in browser, it displays to me xml. It's OK. But, when I try to use this:</p>
  
  <pre><code>@Test
  public void testGetAll() {
      List list = new RestTemplate().getForObject(URL + "all", List.class);
      System.out.println(list);
  }
  </code></pre>
  
  <p>I got</p>
  
  <pre><code>WARNING: GET request for "http://localhost:8080/REST/all" resulted in 500 (Internal Server Error); invoking error handler
  </code></pre>
  
  <p>I tried to debug this. No exceptions during method works. And browser shows me the xml with users.
  What can be wrong? </p>
  
  <p>Also, I want to know, how I can get status code or message from template object (for test)?</p>
  
  <p>Thanks for your answers.</p>
  
  <p>EDITED:</p>
  
  <p>I modified my test method:</p>
  
  <pre><code>@Test
  public void testGetAll() {
      RestTemplate template = new RestTemplate();
  
      List&lt;HttpMessageConverter&lt;?&gt;&gt; messageConverters = new    ArrayList&lt;HttpMessageConverter&lt;?&gt;&gt;();
      Jaxb2RootElementHttpMessageConverter jaxbMessageConverter = new Jaxb2RootElementHttpMessageConverter();
      List&lt;MediaType&gt; mediaTypes = new ArrayList&lt;MediaType&gt;();
      mediaTypes.add(MediaType.APPLICATION_XML);
      jaxbMessageConverter.setSupportedMediaTypes(mediaTypes);
      messageConverters.add(jaxbMessageConverter);
  
      template.setMessageConverters(messageConverters);
      List list = template.getForObject(URL + "all",
              ArrayList.class);
      System.out.println(list);
  }
  </code></pre>
  
  <p>And I got exception:</p>
  
  <pre><code>org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class java.util.ArrayList] and content type [application/xml]
  at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:107)
  at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:496)
  at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:452)
  at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:222)
  at com.nixsolutions.web.service.rest.UserRESTServiceTest.testGetAll(UserRESTServiceTest.java:61)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
  at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
  at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
  at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
  </code></pre>