title: Catch a deserialization exception before a ControllerAdvice
body: <p>Here is a problem: I have a controller that takes an input model. Lets say</p>
  
  <pre><code>public class AppUserUpdateData {
  
    @NotNull
    @Size(min = 1, max = 50)
    protected String login;  
    @JsonDeserialize(using = MyDateTimeDeserializer.class)  
    protected Date startWorkDate;
    *************
    other properties and methods
    *************
  }
  </code></pre>
  
  <p>The problem is when I want to restrict a down board of a date I eventually get an HTTP exception 400 without any messages despite I handle this case in my code!
  here is a controller:</p>
  
  <pre><code> @RequestMapping(
        value = "/users/{userId}", method = RequestMethod.PUT,
        produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody AbstractSuccessResult updateUser(@PathVariable Long userId,
        @RequestBody AppUserUpdateData  appUserUpdateRequest, HttpServletRequest request) {    
      AbstractSuccessResult response = new AbstractSuccessResult();
      appUserService.updateUser(appUserUpdateRequest, userId);
      return response;
    }
  </code></pre>
  
  <p>Here is a Deserializer:</p>
  
  <pre><code>public class MyDateTimeDeserializer extends JsonDeserializer&lt;Date&gt; {
  
    @Override
    public Date deserialize(JsonParser jsonParser, DeserializationContext context)
        throws IOException, JsonProcessingException {
      try {
        return DataTypeHelper.stringToDateTime(jsonParser.getText());
      } catch (MyOwnWrittenException ex) {
        throw ex;
      }
    }  
  }
  </code></pre>
  
  <p>In a <code>DataTypeHelper.stringToDateTime</code> are some validations that are blocking invalid date-strings. 
  And there is a handler for a my exception:</p>
  
  <pre><code>@ControllerAdvice
  public class MyExceptionHandler extends ResponseEntityExceptionHandler {
  
    @ExceptionHandler({ MyOwnWrittenException .class})
    protected ResponseEntity&lt;Object&gt; handleInvalidRequest(RuntimeException exc, 
      WebRequest request) {
  
      MyOwnWrittenException ex = (MyOwnWrittenException) exc;
      BasicErrorMessage message; = new BasicErrorMessage(ex.getMessage());    
      AbstractUnsuccessfulResult result = new AbstractUnsuccessfulResult(message);
      HttpHeaders headers = new HttpHeaders();
      headers.setContentType(MediaType.APPLICATION_JSON);
      return handleExceptionInternal(exc, result, headers, HttpStatus.BAD_REQUEST, request);
    }
  }
  </code></pre>
  
  <p>The problem is that when an exception in a <code>MyDateTimeDeserializer</code> has been thrown it doesn't falling into a <code>MyExceptionHandler</code> but I cannot understand why? What am I doing wrong?
  In the response is just an empty response with a code 400(</p>
  
  <p><strong>UPD</strong>
  Thanks to @Joe Doe's answer the problem has been solved. Here is my updated handler:</p>
  
  <pre><code>@Order(Ordered.HIGHEST_PRECEDENCE)    
  @ControllerAdvice
  public class MyExceptionHandler extends ResponseEntityExceptionHandler {
  
    @ExceptionHandler({ MyOwnWrittenException .class})
    protected ResponseEntity&lt;Object&gt; handleInvalidRequest(RuntimeException exc, 
      WebRequest request) {
  
      MyOwnWrittenException ex = (MyOwnWrittenException) exc;
      BasicErrorMessage message; = new BasicErrorMessage(ex.getMessage());    
      AbstractUnsuccessfulResult result = new AbstractUnsuccessfulResult(message);
      HttpHeaders headers = new HttpHeaders();
      headers.setContentType(MediaType.APPLICATION_JSON);
      return handleExceptionInternal(exc, result, headers, HttpStatus.BAD_REQUEST, request);
    }
  
    @Override
    protected ResponseEntity&lt;Object&gt; handleHttpMessageNotReadable(HttpMessageNotReadableException ex,
        HttpHeaders headers, HttpStatus status, WebRequest request) {
      Throwable cause = ex.getCause();
      String message = null;
      if (cause instanceof JsonMappingException) {
        if (cause.getCause() instanceof MyOwnWrittenException) {
          return handleInvalidRequest((RuntimeException) cause.getCause(), request);
        } else {
          message = cause.getMessage();
        }
      } else {
        message = ex.getMessage();
      }
      AbstractUnsuccessfulResult result = new AbstractUnsuccessfulResult(
          new BasicErrorMessage(message));
      headers.setContentType(MediaType.APPLICATION_JSON);
      return handleExceptionInternal(ex, result, headers, HttpStatus.BAD_REQUEST, request);
    }
  }
  </code></pre>
  
  <p><strong>UPD</strong>
  In my project it doesn't work without annotation <code>@Order(Ordered.HIGHEST_PRECEDENCE)</code> 
  I believe that is because of number of ControllerAdvices in a project</p>