Spring 5 Webflux functional endpoints - How to perform input validation?

As arjen-poutsma said, it seems there is no way of running automated validations on Spring 5 functional endpoints.

Spring documentation is not very clear about this, and it doesn't suggest any approach.

On this Baeldung article, you'll find an idea on how you can run validations using this approach (disclaimer: I'm the writer of the article :) )

In a nutshell, you can follow these steps:

  1. Implement Spring Validators to evaluate your resources
  2. Create an abstract class with the basic procedure that any handler will follow when processing a request, leaving up to the children classes what to do when the data is valid
  3. Make your request handler classes extend this abstract class, implementing this abstract method, stating the body it will be expecting, and what validator needs to be used to validate it

EDIT:

I've been following this related Spring issue, and it seems we now count with official documentation regarding this subject: https://github.com/spring-projects/spring-framework/blob/master/src/docs/asciidoc/web/webflux-functional.adoc#validation

The suggested approach is to use validators as explained in the article.


In Spring version 5.0, there is no automatic way to do validation in functional endpoints, and as such validation must be done manually.

Though there are currently no concrete plans to do so, we might add some sort of validation in the future. But even then it will be an explicit method call, and not an automatic mechanism. Overall, the functional endpoint model is designed to be a lot more explicit than the annotation-based model.