how to custom validator for standard constraints in java
Old not from 2017. May be outdated.
Bean validation provides constraint annotations to check DTO parameters.
However, what if we want to check a parameter type not supported by a standard constraint annotation?
Let’s say, we want to check a LocalDateTime is in the future. But, our parameter type is in String, a type not supported
by the annotation @Future.
Instead of creating a new annotation, we will add configure so that it will support it.
First, let’s create our custom validator:
Then provide this implementation in META-INF/services/javax.validation.ConstraintValidator: