title: Convert JSON payload to xml with SpringBoot
body: <p><strong>I have a controller action written using SpringBoot that handles POST requests for /greeting and returns a String response. My intention is to convert the json payload to xml and eventually hit another webservice with an xml payload. I tried the following to convert json to xml. However the xml conversion never happens. I get a JSON response.</strong></p>
  
  <h2>GreetingController.java</h2>
  
  <pre><code>@RequestMapping(value = "/greeting", method = RequestMethod.POST, consumes = "application/json")
    public String greeting(@RequestBody final Greeting greeting) throws JsonProcessingException
    {
      final ObjectMapper xmlMapper = new ObjectMapper();
      final String xml = xmlMapper.writeValueAsString(greeting);
      return xml;
    }
  </code></pre>
  
  <h2>Greeting.java</h2>
  
  <pre><code>package com.fmr.communication.delivery.stream.model;
  
  import com.fasterxml.jackson.databind.JsonNode;
  
  public class Greeting
  {
    private long id;
    private String content;
    private JsonNode parent;
  
    public String getContent()
    {
      return content;
    }
  
    public long getId()
    {
      return id;
    }
  
    public JsonNode getParent()
    {
      return parent;
    }
  
    public void setContent(final String content)
    {
      this.content = content;
    }
  
    public void setId(final long id)
    {
      this.id = id;
    }
  
    public void setParent(final JsonNode parent)
    {
      this.parent = parent;
    }
  
  }
  </code></pre>
  
  <h2>Request (Also the response I'm getting)</h2>
  
  <pre><code>{
      "id":2,
      "content":"Hello, User!",
      "parent":{  
        "child":{  
           "header":{  
              "attrOne":"value1",
              "attrTwo":"value2"
           },
           "footer":{
              "attrOne":"value1",
              "attrTwo":"value2"
           }
        }
     }
  }
  </code></pre>
  
  <h2>Expected Response</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;root&gt;
     &lt;content&gt;Hello, User!&lt;/content&gt;
     &lt;id&gt;2&lt;/id&gt;
     &lt;parent&gt;
        &lt;child&gt;
           &lt;footer&gt;
              &lt;attrOne&gt;value1&lt;/attrOne&gt;
              &lt;attrTwo&gt;value2&lt;/attrTwo&gt;
           &lt;/footer&gt;
           &lt;header&gt;
              &lt;attrOne&gt;value1&lt;/attrOne&gt;
              &lt;attrTwo&gt;value2&lt;/attrTwo&gt;
           &lt;/header&gt;
        &lt;/child&gt;
     &lt;/parent&gt;
  &lt;/root&gt;
  </code></pre>