title: SpringBoot: Consume & Produce XML with a Custom Serializer + Deserializer
body: <p>I have a SpringBoot Service with:</p>
  
  <p>Model</p>
  
  <pre><code>public class Payload {
      private final String id;
  
      public Payload(String id){
          this.id = id;
      }
  
      public String getId() {
          return this.id;
      }
  }
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>@RestController
  @RequestMapping("/payload")
  public class PayloadController {
  
      @RequestMapping(method = RequestMethod.POST)
      public Payload post(@RequestBody final Payload payload) {
          return payload;
      }
  }
  </code></pre>
  
  <p>I need this Controller to be able to handle JSON &amp; XML requests and respond with the same format.
  This works fine providing I set the <code>Content-Type</code> and <code>Accept</code> headers to the correct media types. </p>
  
  <p>However, my XML payloads need to be in a subtly different structure to my JSON:</p>
  
  <p>XML:</p>
  
  <pre><code>&lt;Payload&gt;
      &lt;id value="some-value"/&gt;
  &lt;/Payload&gt;
  </code></pre>
  
  <p>JSON:</p>
  
  <pre><code>{
      id: "some-value"
  }
  </code></pre>
  
  <p>How do I ensure my <code>id</code> is wrapped in an xml node and has the "value" as an attribute?</p>
  
  <hr>
  
  <p>I have tried using a <code>@JsonSerialize</code> and <code>@JsonDeserialize</code> annotation on my <code>Payload</code> class but as soon as I do this I get the following error when <code>POST</code>ing XML</p>
  
  <pre><code>{
      "timestamp": "2019-10-01T12:06:35.593+0000",
      "status": 415,
      "error": "Unsupported Media Type",
      "message": "Content type 'application/xml;charset=UTF-8' not supported",
      "path": "/payload"
  }
  </code></pre>