title: Spring Boot - how to handle UnrecognizedPropertyException from Jackson manually?
body: <p>So I have a controller that takes input a request body:</p>
  
  <pre><code>@RestController
  @RequestMapping("/foo/bar")
  public class FooBarController {
      @RequestMapping(method = RequestMethod.POST)
      public ResponseEntity&lt;?&gt; doTheFoo(@RequestBody MyDto dto) {
          ...
      }
  }
  </code></pre>
  
  <p>And I have this FooBar:</p>
  
  <pre><code>public clas FooBar {
      @JsonProperty("foo")
      private String foo;
  
      public void setFoo(String foo) { ... }
      public String getFoo() { ... }
  }
  </code></pre>
  
  <p>And I have set in my properties to fail on unknown properties:</p>
  
  <pre><code>spring.jackson.deserialization.fail-on-unknown-properties: true
  </code></pre>
  
  <p>And I also have a handler to try and capture the failure:</p>
  
  <pre><code>@ControllerAdvice
  public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
      @ExceptionHandler(UnrecognizedPropertyException.class)
      public ResponseEntity&lt;?&gt; handleUnrecognizedPropertyException(UnrecognizedPropertyException ex) {
          ...
      }
  }
  </code></pre>
  
  <p>But when I POST to my endpoint with an unknown property (e.g. <code>{"bar": "baz"}</code>), nothing in the GlobalExceptionHandler is run and instead a vanilla 400 BAD REQUEST is returned. How do I intercept the unknown property exception and provide a different response?</p>