Spring 5 Webflux Functional Endpoints - How do I validate input?

According to the current document (5.0.0.RELEASE), Spring Webflux supports validation when working with annotated controllers:

By default, if Bean Validation is present in the classpath - for example. Hibernate Validator, LocalValidatorFactoryBean is registered as a global validator for use with @Valid and Validated on @Controller method arguments.

However, nothing has been said about how to automate it using functional endpoints. In fact, the only example of input processing in the documentation confirms nothing:

public Mono<ServerResponse> createPerson(ServerRequest request) { Mono<Person> person = request.bodyToMono(Person.class); return ServerResponse.ok().build(repository.savePerson(person)); } 

Should we do it manually or is there some kind of automatic way to do this?

+5
source share
1 answer

Spring version 5.0 does not have an automatic way to verify validity at functional endpoints, and therefore such verification must be done manually.

Although there are currently no specific plans to do this, we can add some kind of verification in the future. But even then it will be an explicit method call, not an automatic mechanism. In general, the functional endpoint model is designed much more clearly than the annotation model.

+9
source

Source: https://habr.com/ru/post/1272254/


All Articles