Dynamically set validator for @Constraint - Spring Boot

120 Views Asked by At

The question is simple as that - is it possible to set dynamically/programmatically a validator for the javax.validation.@Constraint, based on, lets say a flag, from the properties in a Spring Boot application?

My attempt was to declare a custom Validator as interface, which extends ConstraintValidator, and then have 2 specific classes implementing it, each with its own validation method. The type to be validated is the same. But it wouldn't allow me to do that for the interface, nor abstract classes - looks like @Constraint accepts only classes that can be instantiated right away.

Nor I found any example for such approach.

Any idea if it's even possible?

0

There are 0 best solutions below