title: exception message for missing @RequestBody method parameter
body: <p>Firstly,if you have any ideas or solution, thank you to present here.
  I use @RequestBody on one of my controllers for a required parameter, I need some useful way of saying which parameter was missing if it's not there. 
  When there are some parameters missing, it will throw the NullPointerException, SO I create a new exception to instance of this null exception (please see the httpemun and the httphandler)
  These are the primary codes which referring to this question.</p>
  
  <p>my controller:</p>
  
  <pre><code>public ResponseEntity&lt;?&gt; createOrder(@RequestBody Cart cart) throws Exception {
    // ......
  }
  </code></pre>
  
  <p>my entity cart:</p>
  
  <pre><code>public class Cart{
        private String channel
        private String cartId;
        private String status;
        private String currency;
  
        getters...
        setters...
  
      }
  </code></pre>
  
  <p>my Http emun class:</p>
  
  <pre><code>public enum HttpStatusEnum {
      CRE_CART_INCOMPLETE_BODY(400,"E001","Incomplete request body","");
      private HttpStatusEnum(int statusCode, String code,
                             String message, String detail) {
          this.statusCode = statusCode;
          this.code = code;
          this.message = message;
          this.detail = detail;
      }
  
      private final int statusCode;
      private final String code;
      private final String message;
      private String detail;
  
      public int getStatusCode() {
          return statusCode;
      }
  
      public String getCode() {
          return code;
      }
      public String getMessage() {
          return message;
      }
      public void setDetail(String detail) {      
          this.detail = detail;
      }
  
      public String getDetail() {     
          if(detail.isEmpty()) {
              return message;
          }else {
              return detail;
          }
      }
  }
  </code></pre>
  
  <p>I also have one exception handle</p>
  
  <pre><code>@ControllerAdvice
  public class GlobalExceptionHandler {
      private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
      @ExceptionHandler(value = Exception.class)
      @ResponseBody
      public ResponseEntity&lt;Object&gt; defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {
    if(e instanceof NullPointerException)
      {if(req.getRequestURL().toString().contains(HttpSourceEnum.CART.toString()) &amp;&amp; req.getMethod().equals(RequestMethod.POST.toString())){   
              errorBodyVo.setMessage(HttpStatusEnum.CRE_CART_INCOMPLETE_BODY.getMessage());
              errorBodyVo.setDetails(HttpStatusEnum.CRE_CART_INCOMPLETE_BODY.getDetail());  
              errorBodyVo.setCode(HttpStatusEnum.CRE_CART_INCOMPLETE_BODY.getCode());         
          }else {        
              errorBodyVo.setMessage(HttpStatusEnum.COMMON_MISSING_FIELD.getMessage());
              errorBodyVo.setDetails(HttpStatusEnum.COMMON_MISSING_FIELD.getDetail());  
              errorBodyVo.setCode(HttpStatusEnum.COMMON_MISSING_FIELD.getCode());
          }    
          httpStatus = HttpStatus.BAD_REQUEST;
      }
  }
  </code></pre>
  
  <p>right now,
  my API request is:</p>
  
  <pre><code>{
    "channel": "XX",
    "cartId": "109",
    "status": "1",
  }
  </code></pre>
  
  <p>I receive the API response just like below:</p>
  
  <pre><code>{
      "error": {
          "code": "E001",
          "message": "Incomplete request body",
          "details": ""
      }
  }
  </code></pre>
  
  <p>but it doesn't match my expect.
  if the channel is missing in my request like below:</p>
  
  <pre><code>{
    "cartId": "109",
    "status": "1",
  }
  </code></pre>
  
  <p>I expect to show "Required request body content is missing: Channel" in the details:</p>
  
  <pre><code>{
      "error": {
          "code": "E001",
          "message": "Incomplete request body",
          "details": "Required request body content is missing: Channel"
      }
  }
  </code></pre>
  
  <p>How could I do that? Thanks guys!</p>