title: RestTemplate. Unmarshalling JaxB object from octet-stream
body: <p>I have need to send request to service and parse response as a jaxb object. This is service call code:</p>
  
  <pre><code>        ProviderResponse response = restTemplate.postForObject(
              URL,
              request,
              ProviderResponse.class
          );
  </code></pre>
  
  <p><code>request</code> and <code>response</code> are JAXB objects. This is spring configuration:</p>
  
  <pre><code>&lt;mvc:annotation-driven&gt;
      &lt;mvc:message-converters&gt;
          &lt;bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/&gt;
          &lt;bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"&gt;
              &lt;property name="marshaller" ref="jaxbMarshaller"/&gt;
              &lt;property name="unmarshaller" ref="jaxbMarshaller"/&gt;
          &lt;/bean&gt;
      &lt;/mvc:message-converters&gt;
  &lt;/mvc:annotation-driven&gt;
  
  
  &lt;bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"&gt;
      &lt;property name="classesToBeBound"&gt;
          &lt;list&gt;
              &lt;value&gt;com.service.data.ProviderRequest&lt;/value&gt;
              &lt;value&gt;com.service.data.ProviderResponse&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>When I run this code, I get an exception:</p>
  
  <pre><code>org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class com.service.data.ProviderResponse] and content type [application/octet-stream]
  </code></pre>
  
  <p>I tried to do this way:</p>
  
  <pre><code>        String responseStr = restTemplate.postForObject(
              URL,
              request,
              String.class
          );
  
          ProviderResponse response = stringToJaxb(responseStr, ProviderResponse.class);
  </code></pre>
  
  <p>and it works fine, but I don't think that it's a good solution.
  Maybe it can be fixed by spring config?</p>
  
  <p>UPD</p>
  
  <p>ProviderResponse class:</p>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlType(name = "", propOrder = {
      "header",
      "body"
  })
  @XmlRootElement(name = "providerResponse")
  public class ProviderResponse {
  
      @XmlElement(required = true)
      protected String header;
      @XmlElement(required = true)
      protected ProviderResponse.Body body;
  
  
      public String getHeader() {
          return header;
      }
  
  
      public void setHeader(String value) {
          this.header = value;
      }
  
  
      public ProviderResponse.Body getBody() {
          return body;
      }
  
  
      public void setBody(ProviderResponse.Body value) {
          this.body = value;
      }
  
  
      @XmlAccessorType(XmlAccessType.FIELD)
      @XmlType(name = "", propOrder = {
          "code",
          "serviceStatus"
      })
      public static class Body {
  
          @XmlElement(required = true)
          protected String code;
          protected String serviceStatus;
  
  
          public String getCode() {
              return code;
          }
  
          public void setCode(String value) {
              this.code = value;
          }
  
          public String getServiceStatus() {
              return serviceStatus;
          }
  
  
          public void setServiceStatus(String value) {
              this.serviceStatus = value;
          }
  
      }
  
  }
  </code></pre>