title: Send POST request with JSON data Spring boot
body: <p>I trying to send a post request with json data in a particular format using Spring boot. I am not getting data in expected format. Please help e resolve it. Thanks in advance.</p>
  <pre><code>class UserService{
  public void sendRequest(User data){
    HttpHeaders header = new HttpHeaders();
    mapHeaders.set(&quot;Content-Type&quot;,&quot;application/json&quot;);
    Map&lt;String,User&gt; m= new HashMap&lt;String,User&gt;();
    m.put(&quot;request&quot;,data);
    //print m i.e. payload being sent
    HttpEntity entity = new HttpEntity&lt;Object&gt;(m, header);
    String url = some url here
    ResponseEntity&lt;Object&gt; response = restTemplate.exchange(url, httpMethod, entity, 
     Object.class);
     }
  }
  
  class User{
  private String firstName;
  private String lastName;
  
  }
  
  
  </code></pre>
  <p>While printing payload it displays payload as:</p>
  <pre><code>{request=User(firstName=Raj,lastName=Kumar)}
  </code></pre>
  <p>I want the data as</p>
  <pre><code>{request={firstName=Raj,lastName=Kumar}}
  </code></pre>