title: Spring Resttemplate exchange method to call a PATCH request
body: <p>I have a java 8 application with spring framework. We need to call a patch operation using REST from our application.</p>
  
  <p>The code snippet is as follows:</p>
  
  <pre><code>import com.xyz.myobject.ResponseAdmission;
  import com.xyz.myobject.RequestAdmission;
  
  @Repository
  public class AdmissionRepository {
  
     @Autowired
     private RestTemplate restTemplate;
  
     public ResponseObject updateAdmission(RequestAdmission requestAdmission, String admissionId) {
  
     UriBuilder uriBuilder =  UriBuilder.fromUri("https://admissionportal.com").path("admission").path("admissionId="+admissionId);
  
     HttpEntity&lt;RequestAdmission&gt; admissionEntity = new HttpEntity&lt;&gt;(requestAdmission, this.getHeaders);
  
     ResponseEntity&lt;ResponseAdmission&gt; responseEntity = this.restServiceESBSupport.exchange(uriBuilder.build(), HttpMethod.PATCH, admissionEntity , ResponseAdmission.class);
  
     return responseEntity.getBody();
  
  }
  
  public MultiValueMap&lt;String, String&gt; getHeaders() {
          MultiValueMap&lt;String, String&gt; headers = new LinkedMultiValueMap&lt;&gt;();
          headers.add("Accept", "application/xml");
          headers.add("Content-Type", "application/xml");
          return headers;
      }
  
  }
  </code></pre>
  
  <p>When I execute the above code, when the line with 'exchange' keyword is executed, it gives an error as :</p>
  
  <p><strong>org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter found for request type [com.xyz.myobject.RequestAdmission] and content type [application/xml]</strong></p>
  
  <p>When I debugged the code, the restTemplate has the following 7 convertors registered:</p>
  
  <pre><code>ByteArrayHttpMessageConverter,
  StringHttpMessageConverter,
  ResourceHttpMessageConverter,
  SourceHttpMessageConverter,
  AllEncompassingFormHttpMessageConverter,
  Jaxb2RootElementHttpMessageConverter,
  MappingJackson2HttpMessageConverter
  </code></pre>
  
  <p>I also tried to add following line:</p>
  
  <pre><code>this.restTemplate.getMessageConverters().add(new Jaxb2RootElementHttpMessageConverter());
  </code></pre>
  
  <p>But still not working.</p>
  
  <p><strong>RequestAdmission and ResponseAdmission are the JAXB POJO objects generated from xsds.</strong></p>
  
  <p>The webservice accepts the request in form of xml and response is also in form of xml.</p>
  
  <p>Please advise.</p>