title: Request Body for Post Method in Spring Controller
body: <p>I need to implement a post endpoint which accepts a object(json). But some of the parameters in the object are optional. So when i try to make api call It is not mapping to that respective method.</p>
  
  <p>It was showing Page not found Err : 404</p>
  
  <p>Request body which i am sending contains only two fields, as the rest are optional.</p>
  
  <p>Pojo for the object </p>
  
  <pre><code>public class Post {
    private String owner;
  
    private String activity;
  
    private Boolean edited;
  
    private String clientApp;
  
    private String serviceProvider;
  
    private long id;
  
    private Text text;
  
    public static class Text {
  
      private String text;
  
      public String getText() {
        return text;
      }
  
      public void setText(String text) {
        this.text = text;
      }
    }
  
    public String getOwner() {
      return owner;
    }
  
    public void setOwner(String owner) {
      this.owner = owner;
    }
  
    public String getActivity() {
      return activity;
    }
  
    public void setActivity(String activity) {
      this.activity = activity;
    }
  
    public Boolean getEdited() {
      return edited;
    }
  
    public void setEdited(Boolean edited) {
      this.edited = edited;
    }
  
    public String getClientApp() {
      return clientApp;
    }
  
    public void setClientApp(String clientApp) {
      this.clientApp = clientApp;
    }
  
    public String getServiceProvider() {
      return serviceProvider;
    }
  
    public void setServiceProvider(String serviceProvider) {
      this.serviceProvider = serviceProvider;
    }
  
    public long getId() {
      return id;
    }
  
    public void setId(long id) {
      this.id = id;
    }
  
    public Text getText() {
      return text;
    }
  
    public void setText(Text text) {
      this.text = text;
    }
  
  }
  </code></pre>
  
  <p>Spring controller:</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST, value="/publish/post",consumes = MediaType.APPLICATION_JSON_VALUE)
      public String publish(
        @RequestBody Post map) {
        logger.info("Post method")
        return "Completed";
      }
  </code></pre>
  
  <p>Curl Command : </p>
  
  <pre><code>curl -X POST \
    http://localhost:4569/rest/publish/post \
    -H 'Content-Type: application/json' \  
    -d '{
      "owner": "Owner of the Company",
      "text": {
          "text": "Png new image"
      }
  }'
  </code></pre>
  
  <p>Payload </p>
  
  <pre><code>{
  "owner": "Owner of the Company",
  "text": {
      "text": "Png new image"
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Rest Controller : </p>
  
  <pre><code>@RestController
  @RequestMapping("/rest")
  public class SocialController {
  
      private static final Logger logger = LoggerFactory.getLogger(SocialController.class);
  
      @RequestMapping(method = RequestMethod.POST, value="/publish/post",consumes = MediaType.APPLICATION_JSON_VALUE)
      public String publish(
        @RequestBody Post map) {
        logger.info("Post method")
        return "Completed";
      }
  }
  </code></pre>