title: SprintBoot REST API to return XML as response
body: <p>I am learning SpringBoot and have this piece of code that is able to understand incoming JSON responses and return a JSON response to the client ( POSTMAN ). I am trying to get a feel of SpringBoot and wanted to configure it to return an XML response instead.</p>
  <pre><code>@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces =  {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
      public ResponseEntity&lt;Movie&gt; addMovies(@RequestBody Movie movie) {
          service.addToMovies(movie);
  
          // Return a ResponseEntity instead.
          return new ResponseEntity&lt;Movie&gt;(movie, HttpStatus.OK);
  }
  </code></pre>
  <p>If I set Accept HTTP header with value application/xml, I am getting this error:</p>
  <pre><code>Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class io.fireacademy.restapi.restapiaws.models.Movie] with preset Content-Type 'null']
  </code></pre>
  <p>Not sure why this error is coming up. Also, why does it say, Resolved?.
  I have looked at existing threads over this and see that my pom.xml already has the entries:</p>
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
      &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
  &lt;/dependency&gt;
  </code></pre>
  <p>My SpringBoot controller class code:</p>
  <pre><code>package io.fireacademy.restapi.restapiaws.controllers;
  
  import io.fireacademy.restapi.restapiaws.models.Movie;
  import io.fireacademy.restapi.restapiaws.services.MovieRecommendationService;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.MediaType;
  import org.springframework.http.ResponseEntity;
  import org.springframework.web.bind.annotation.*;
  
  import java.util.List;
  
  @RestController
  @RequestMapping(&quot;/movies&quot;)
  public class RestAPIController {
  
      @Autowired
      private MovieRecommendationService service;
  
      // When to return a ResponseEntity
      // Read https://stackoverflow.com/questions/49673660/return-responseentity-vs-returning-pojo
  
      @GetMapping
      public List&lt;Movie&gt; getMovies() {
          return service.getMovies();
      }
  
      // Learning: The annotation @PathVariable is needed to inject the value in the URL onto the variable.
      @GetMapping(path=&quot;/{movieId}&quot;)
      public ResponseEntity&lt;Movie&gt; getMovieById(@PathVariable String movieId) {
          return new ResponseEntity&lt;Movie&gt;(service.getMovie(Integer.parseInt(movieId)), HttpStatus.OK);
      }
  
      // TODO: Why is a List&lt;Movie&gt; failing in POST API and not in GET API
      // TODO: What is the use of produces/consumes
      // Learning: The client need to set Content-Type HTTP header set so that the server can understand how to process the body data.
      @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces =  {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
      public ResponseEntity&lt;Movie&gt; addMovies(@RequestBody Movie movie) {
          service.addToMovies(movie);
  
          // Return a ResponseEntity instead.
          return new ResponseEntity&lt;Movie&gt;(movie, HttpStatus.OK);
      }
  
      @PutMapping(path=&quot;/{movieId}&quot;)
      public ResponseEntity&lt;Movie&gt; updateMovies(@PathVariable String movieId, @RequestBody Movie movie) {
  
          // Return a ResponseEntity instead.
          return new ResponseEntity&lt;Movie&gt;(service.updateAMovie(Integer.parseInt(movieId), movie), HttpStatus.OK);
      }
  
      @DeleteMapping(path=&quot;/{movieId}&quot;)
      public ResponseEntity&lt;Movie&gt; deleteMovies(@PathVariable String movieId) {
  
          // Return a ResponseEntity instead.
          return new ResponseEntity&lt;Movie&gt;(service.removeAMovie(Integer.parseInt(movieId)), HttpStatus.OK);
      }
  
      // TODO: Integrate this onto a Javascript code
  }
  </code></pre>
  <p>I also updated the consumer too. Same result though.</p>
  <pre><code>@PostMapping(consumes = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE }, produces =  {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
  </code></pre>
  <p>Please give me any clues.</p>