0

I have a custom Annotation constraint , but I want it to be checked only if the other constraint is valid .For example:

@NotNull
private String propertyA;
@Digits
private String propertyB;

if propertyA is null , i don't want "@Digits"on propertyB to be checked.

How can i solve the problem? Thanks.

Peter Ni
  • 43
  • 4

1 Answers1

0

You can use the "when" attribute, e.g.

@NotNull
private String propertyA;

@Digits(when="groovy:_this.propertyA!=null")
private String propertyB;

This example requires the Groovy runtime to be in the classpath. You can also use another scripting language, see http://oval.sourceforge.net/userguide.html#declaring-conditional-constraints

Seb T
  • 795
  • 8
  • 16