title: org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'text/xml;charset=UTF-8' not supported for bodyType
body: <p>using Java 11, SpringBoot 2, WebFlux, WebClient and Jackson</p>
  
  <p>trying to use Spring WebClient to consume a Web service endpoint that returns XML, content type: 'text/xml;charset=UTF-8'</p>
  
  <p>Jackson XML dependency in the project's pom.xml:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;com.fasterxml.jackson.dataformat&lt;/groupId&gt;
      &lt;artifactId&gt;jackson-dataformat-xml&lt;/artifactId&gt;
      &lt;version&gt;2.9.9&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>WebClient code that triggers a request to external API and builds the response:</p>
  
  <pre><code>        WebClient.builder()
                  .baseUrl(url)
                  .build()
                  .get()
                  .uri(builder.toUriString(), 1L)
                  .accept(TEXT_XML)
                  .header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_XML_VALUE)
                  .acceptCharset(Charset.forName("UTF-8"))
                  .exchange()
                  .flatMap(x -&gt; x.bodyToMono(ServiceResponse.class))
                  .flatMap(x -&gt; buildResponse(x));
  </code></pre>
  
  <p>ServiceResponse class (a simple POJO):</p>
  
  <pre><code>public class ServiceResponse {
  
      private String ack;
      private String version;
      private String timestamp;
  // .. getters and setters
  </code></pre>
  
  <p>resulting error:</p>
  
  <blockquote>
    <p>org.springframework.web.reactive.function.UnsupportedMediaTypeException:
    <strong>Content type 'text/xml;charset=UTF-8' not supported</strong> for
    bodyType=com.sample.service.model.ServiceResponse at
    org.springframework.web.reactive.function.BodyExtractors.lambda$readWithMessageReaders$12(BodyExtractors.java:201)
    ~[spring-webflux-5.1.8.RELEASE.jar:5.1.8.RELEASE]     at
    java.base/java.util.Optional.orElseGet(Optional.java:369) ~[na:na]    at
    org.springframework.web.reactive.function.BodyExtractors.readWithMessageReaders(BodyExtractors.java:197)
    ~[spring-webflux-5.1.8.RELEASE.jar:5.1.8.RELEASE]     at
    org.springframework.web.reactive.function.BodyExtractors.lambda$toMono$2(BodyExtractors.java:85)
    ~[spring-webflux-5.1.8.RELEASE.jar:5.1.8.RELEASE]     at
    org.springframework.web.reactive.function.client.DefaultClientResponse.body(DefaultClientResponse.java:95)
    ~[spring-webflux-5.1.8.RELEASE.jar:5.1.8.RELEASE]     at
    org.springframework.web.reactive.function.client.DefaultClientResponse.bodyToMono(DefaultClientResponse.java:113)
    ~[spring-webflux-5.1.8.RELEASE.jar:5.1.8.RELEASE]</p>
  </blockquote>
  
  <p>how to properly consume the type of response: Content-type <strong>'text/xml;charset=UTF-8'</strong>  ?</p>