I'm trying to validate JSON (passed by a client as a request body) before it is converted into a model in Controller method.
If validation passes then return nothing, let the process continue as it was (spring boot to convert JSON into a model marked as @RequestBody). Throw error in case validation fails (everit-org/json-schema).
I tried to two way:
Implement
HandlerMethodArgumentResolver
, butresolveArgument()
doesn't give request body details as it is already read and stored inContentCachingRequestWrapper
.NOTE:
inputStream
inContentCachingRequestWrapper
doesn't have any request body details.Using spring
Interceptor
. But this doesn't help me to find request body type passed in the request. As JSON schema is different for each request.
Any other approaches I can try with?