title: Convert Map to JSON using Jackson
body: <p>How can I convert a Map to a valid JSON using Jackson?</p>
  
  <p>I am doing it using Google's GSON via a Spring Boot REST Post method...</p>
  
  <p>Here's the RESTful Web Service:</p>
  
  <pre><code>import java.util.Map;
  
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RestController;
  
  import com.fasterxml.jackson.core.JsonFactory;
  import com.fasterxml.jackson.core.JsonParser;
  import com.google.gson.Gson;
  
  @RestController
  @RequestMapping("/myservice")
  public class ValidationService {    
  
      @RequestMapping(value="/validate", method = RequestMethod.POST)
      public void validate(@RequestBody Map&lt;String, Object&gt; payload) throws Exception {
          Gson gson = new Gson();
          String json = gson.toJson(payload); 
          System.out.println(json);
      }
  }
  </code></pre>
  
  <p>So, when I invoke it using this:</p>
  
  <pre><code>curl -H "Accept: application/json" -H "Content-type: application/json" \
  -X POST -d '{"name":"value"}' http://localhost:8080/myservice/validate
  </code></pre>
  
  <p>Receive the following to stdout (this is exactly what I want):</p>
  
  <pre><code>{"name":"value"}
  </code></pre>
  
  <p>Is there a better way to do this using Jackson instead of Google's Gson and / or am I going about it the wrong way altogether?</p>