'javax validation OneOf constraint

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;


Solution 1:[1]

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:

Solution 2:[2]

If you are using hibernate-validator, you can declare new annotation using @ConstraintComposition. This is a good example here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Slava Semushin
Solution 2 linarkou