Is there an annotation in javax validation, so it should constraint that value is one of predefined values. Example
@OneOf(values = "12-14m, 16m, 18m")
private String size;
Is there an annotation in javax validation, so it should constraint that value is one of predefined values. Example
@OneOf(values = "12-14m, 16m, 18m")
private String size;
If you are using hibernate-validator, you can declare new annotation using @ConstraintComposition
. This is a good example here.
No, there is no such constraint and you have to write it's own.
Here is the example that does mostly the same but opposite
@DenyValues
:annotation usage on a class: https://github.com/php-coder/mystamps/blob/66a2254e6d78c03d0b50531752d860efe784a1fd/src/main/java/ru/mystamps/web/controller/dto/AddCountryForm.java#L87
annotation definition: https://github.com/php-coder/mystamps/blob/66a2254e6d78c03d0b50531752d860efe784a1fd/src/main/java/ru/mystamps/web/support/beanvalidation/DenyValues.java#L35-L44
validator implementation: https://github.com/php-coder/mystamps/blob/66a2254e6d78c03d0b50531752d860efe784a1fd/src/main/java/ru/mystamps/web/support/beanvalidation/DenyValuesValidator.java#L26-L51