I need to do a completely dynamic validation where I can specify to validate each field plus a set of constraints to validate the field against. I cannot use the annotations at all. I know validateProperty() exists but I don’t see how I can tell it which constraints need to be used. I need the following API:
The reason I can’t use annotations:
-validation is needed on a POJO lib which must not pull any other maven dependencies
-same property can be nullable or notnull depending on the API endpoint being called…therefore need for dynamic validation
You can’t enable or disable constraints so you would have to redefine the metadata each time at runtime, which is not a good idea.
If I were you, I would use groups: e.g. define the constraints once and for all with groups and when validating enable one or the other group depending on what you need.
The programmatic API looks like exactly what I need. I can just make an ApplicationScoped Validator producer for each configuration I need and inject them both via qualifiers. This way the config will only be setup twice on startup and not on each request. I think it will work out… thanks!