I'm using ResponseEntityExceptionHandler
in a Spring Boot-based RESTFul application, to capture errors in a single place and output a consistent error payload.
Everything works as expected. A class that extends ResponseEntityExceptionHandler
can override handleMethodArgumentNotValid
in order to "react" on a client sending a message that doesn't pass the validation.
Currently, validation is triggered by annotating the Request Body with the @Valid
annotation.
Everything works as expected. If a client POST a JSON document which doesn't validate, the code in the handleMethodArgumentNotValid
is executed correctly.
Now, for monitoring purposes, I would like to log the invalid JSON. Obviously, the original InputStream
is closed.
I solved a similar problem recently by sublcassing MappingJackson2HttpMessageConverter
, but in the case in the link I needed to "hook" into the validation process and thrown a custom exception containing the invalid JSON document.
Any pointers?