0

I am looking for a sample code where a field is annotated with multiple validation annotations (JSR and custom). My requirement is that if validation for one annotation fails, the other annotations should not be triggered.

@NotNull
@Size(min=2, max=2)
@Attribute(value="OCC_TYP")
private String occupationType;

The @Attribute annotation is a custom validation which checks the value of the field with a column.

This @Attribute should only be triggered if other two validation fails. Right now, when I pass a value 'D' then the error message for size is displayed as well the error message for @Attribute is displayed.

  • Have a look at [JSR 303 Validation, If one field equals “something”, then these other fields should not be null](https://stackoverflow.com/q/9284450/5698098); in particular [this answer](https://stackoverflow.com/a/37747771/5698098). Possibly that will already solve your requirement. – Ivo Mori Aug 03 '20 at 23:35
  • Thanks , but in my case the @Attribute should only be triggered if the JSR validation fails. I am looking for something where the result of an annotation can be used to trigger other annotation for the same field – Shwetali Khandelwal Aug 04 '20 at 14:55
  • @ShwetaliKhandelwal Actually their this no order of annotation execution defined. A way can be - check other annotation condition inside your custom annotation's validator – Eklavya Aug 04 '20 at 19:59

0 Answers0