How to disable auto validation of request in Spring boot controller

270 Views Asked by At

I have some DTO object with validation annotations:

MyDto { 
@NotBlank(message = "subscription name is empty")
@Size(max = Constants.SUBSCRIPTION_NAME_MAX_LENGTH, message = "size must not exceed 64 symbols")
String name;
}

Also I have wrapper class for the MyDto:

MyRequest {
    @Size(min = 1, max = 10, message = "My dto list must contain from 1 to 10 items")
    List<@Valid MyDto> dtos;
}

And I finally have controller:

@PostMapping("/doSomething")
 @ResponseStatus(HttpStatus.MULTI_STATUS)
 public Flux<Result> doSomething(@RequestBody @Valid MyRequest request) { //doing something }

                                            

Validation works fine but at some point I want to do manual validation of MyDto using provided validator. I expect if remove @Valid annotations from controller method and from MyRequest wrapper class it will not do automatic validation. However, when I remove all these @Valid annotations from those places and call controller, spring boot does the validation anyway.

Most likely I am missing something but don't know what...Will appreciate if somebody helps...

0

There are 0 best solutions below