title: How do I enable strict validation of JSON / Jackson @RequestBody in Spring Boot REST API?
body: <p>How do I throw an error if extra parameters are specified in the JSON request? For example, "xxx" is not a valid parameter or in the <code>@RequestBody</code> object.</p>
  
  <blockquote>
    <p>$ curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" -d '{"apiKey": "'$APIKEY'", "email": "name@example.com", <strong>"xxx": "yyy"</strong>}' localhost:8080/api/v2/stats</p>
  </blockquote>
  
  <p>I tried adding <code>@Validated</code> to the interface, but it didn't help.</p>
  
  <pre><code>@RequestMapping(value = "/api/v2/stats", method = RequestMethod.POST, produces = "application/json")
  public ResponseEntity&lt;DataResponse&gt; stats(Principal principal, @Validated @RequestBody ApiParams apiParams) throws ApiException;
  </code></pre>
  
  <p>I would like to enable a 'strict' mode so that it will give an error if extra, spurious parameters exist in the request. I could find no way to do this. I found ways to ensure the valid parameters do exist, but no way to ensure there are not extra parameters.</p>
  
  <hr>
  
  <pre><code>public class ApiParams extends Keyable {
  
      @ApiModelProperty(notes = "email of user", required = true)
      String email;
  </code></pre>
  
  <hr>
  
  <pre><code>public abstract class Keyable {
  
      @ApiModelProperty(notes = "API key", required = true)
      @NotNull
      String apiKey;
  </code></pre>
  
  <p>Spring Boot 1.5.20</p>