Consider:
@PostMapping("/track")
public void sendTopicCallback(@RequestBody @Validated Request request): CompletableFuture<ResponseEntity<Void>>
And Request is:
public class Request {
@Valid
private List<MyObjects> objects;
}
How to validate request but instead of returning 400 error code get valid object List and List of errors mapped with raw data?
I am sitting in the train and have no PC with me, so I can just point you in a direction.
What happens in Spring internally, is that a
ConstraintViolationExceptionis thrown. This exception contains all violations found by the validator. This information can be used to calculate the information you need.Second thing that happens when an exception is thrown by a
RestControllerit is handled by an exception handler which maps it to an appropiate http response. If no handler is defined a default handler is used.There are multiple ways to define such a handler, this is best explained in the official documentation.
There you can define a handler for the
ConstraintViolationExceptionwhere you create your desired response.