title: Spring rest post service sending null values as variable
body: <p>I am new to Spring MVC and I am exposing REST services. My <code>GET</code> services are working fine but the <code>POST</code> call from Postman is sending empty <code>null</code> values as fields. </p>
  
  <p>Below is a sample REST service using various forms of <code>POST</code> annotations. I'm stuck on this for the past 3 days. Please help.</p>
  
  <pre><code>package com.cgi.ehr.rest;
  
  import javax.ejb.EJB;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.MediaType;
  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.ResponseBody;
  import org.springframework.web.bind.annotation.RestController;
  import com.cgi.ehr.services.dao.UserDetailsDAO;
  import com.cgi.test.dto.InputDto;
  
  @RestController
  @RequestMapping("/bookmarks")
  public class CheckingService {
  
      @EJB
      UserDetailsDAO userDetailsDAO;
  
      @RequestMapping(value = "/bookmark", method = RequestMethod.GET)
  
      public InputDto testM() {
  
          return userDetailsDAO.testMethod();
      }
  
      @RequestMapping(value = "/testM2", method = RequestMethod.GET,headers="Accept=*/*",  produces="application/json")
      //@Produces(MediaType.APPLICATION_JSON)
      public InputDto testM2() {
          InputDto d = new InputDto("1","2");
          return d;
      }
  
      @RequestMapping(value = "/bookmarkPost", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON)
      @Produces(MediaType.APPLICATION_JSON)
      //@ResponseBody
      public InputDto testPost(InputDto inputDto) {
          String age = inputDto.getTestAge();
          String name = inputDto.getTestname();
          InputDto dto = new InputDto();
          dto.setTestAge(age + "gotback");
          dto.setTestname(inputDto.getTestname() + "gotback");
  
          return dto;
      }
  
  
      @RequestMapping(value = "/bookmarkPost1", method = RequestMethod.POST)
      public InputDto testPost1(InputDto inputDto) {
          String age = inputDto.getTestAge();
          String name = inputDto.getTestname();
          InputDto dto = new InputDto();
          dto.setTestAge(age + "gotback");
          dto.setTestname(inputDto.getTestname() + "gotback");
  
          return dto;
      }
  
  
      @RequestMapping(value = "/person", method = RequestMethod.POST, headers = "Accept=application/xml, application/json")
      public @ResponseBody InputDto addPerson(@RequestBody InputDto inputDto) {
          return inputDto;
      }
  
  }
  `
  
      package com.cgi.test.dto;
  
  import java.io.Serializable;
  
  import javax.xml.bind.annotation.XmlRootElement;
  
  @XmlRootElement
  public class InputDto implements Serializable{
  
  
      /**
       * 
       */
      private static final long serialVersionUID = 1L;
      private String testname;
      private String testAge;
      public String getTestname() {
          return testname;
      }
      public void setTestname(String testname) {
          this.testname = testname;
      }
      public String getTestAge() {
          return testAge;
      }
      public void setTestAge(String testAge) {
          this.testAge = testAge;
      }
      public InputDto() {
          super();
      }
      public InputDto(String testname, String testAge) {
  
          this.testname = testname;
          this.testAge = testAge;
      }
  
  
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/I8yva.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I8yva.png" alt="enter image description here"></a></p>