Skip to content
Advertisement

Spring ControllerAdvice does not return response body?

I have the following ControllerAdvice, that handles JsonParseException (I use Spring and Jackson)

JavaScript

Fore some reason, It doesn’t work when I send a bad json request to the server, only returns 400. When I change the HttpStatus, it still returns 400 so it seems like the advice doesn’t really run.

Advertisement

Answer

ResponseEntityExceptionHandler already implements a lot of different ExceptionHandlers. HttpMessageNotReadableException is one of them:

JavaScript

Simply remove the inheritance:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement