title: Not getting exception while passing invalid json request body to rest api in spring boot
body: <p>I have created one rest API in spring-boot, the problem is that I am taking 4 parameters as a requestbody argument as a JSON object.</p>
  
  <p>Now if I pass the JSON object with 5 parameters than my API still call, no assertion exception occurs while serializing the JSON object.
  I have one dto class as below with constructor</p>
  
  <pre><code>public class testDto{
     @NotNull(message = "fistName can not be null.")
     private String fistName;
     @NotNull(message = "lastName can not be null.")
     private String lastName;
     private String nickName;
  
     public testDto() {
      }
  
      public testDto(@NotNull(message = "fistName can not be null.") final String fistName ,@NotNull(message = "lastName can not be null.") final String lastName , final String nickName){
        super();
        this.fistName = fistName;
        this.lastName = lastName;
        this.nickName = nickName;
      }
  }
  </code></pre>
  
  <p><strong>My restapi</strong> as below,</p>
  
  <pre><code>@PostMapping(path ={ "/api/v1/user"}, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
  public ResponseEntity&lt;Object&gt; saveUser(
              @Valid @RequestBody(required = true) final testDto dto) throws Exception {
  }
  </code></pre>
  
  <p>Now while calling my API I am <strong>passing request body</strong> as below</p>
  
  <pre><code>{
        "fistName" : "abc",
        "lastName" : "xyz",
        "nickName" : "pqr",
        "age" : 25
  }
  </code></pre>
  
  <p>Now here when I pass <code>age</code> parameter and call the API, my API still working instead of throwing an exception for No any constructor found as I have passed age which is not a member of my dto class.</p>
  
  <p><strong>Expected result:</strong> don't allow to call API
  <strong>Actual result:</strong> Allow me to call API</p>
  
  <p><strong>I have also tried</strong> with assertion exception declaration and binding exception but not getting any success.</p>
  
  <p>also set the property </p>
  
  <pre><code>spring.mvc.throw-exception-if-no-handler-found=true
  spring.resources.add-mappings=false
  </code></pre>