I have a simple bean with enum
field
public class TestBean{
@Pattern(regexp = \"A|B\") //does not work
private TestEnum testField;
//getter
If you want to put the constraint on testField you need a custom validator. None of the default ones handle enums.
As a workaround you could add a getter method which returns the string value of the enum
public class TestBean{
private TestEnum testField;
//getters + setters
@Pattern(regexp = "A|B") //does not work
private String getTestFieldName() {
return testField.name();
}
}
A custom validator is probably the cleaner solution though.