Search code examples
javavalidationoval

Oval - Multiple ValidateWithMethod / complex custom validations with different messages?


I am trying to use @ValidateWithMethod to validate a property. I have two very different custom validations. I want to put them in separate methods so that I can have different messages. However, placing two separate @ValidateWithMethod attributes results in a 'duplicate annotation' compilation error.

What is the thing you're supposed to do in this scenario?


Solution

  • I found the annotation syntax to be a bit tricky to figure out so I'm adding an example:

      @ValidateWithMethod.List(value={
        @ValidateWithMethod(methodName="foo", parameterType=String.class, ignoreIfNull=true, message="FooError"),
        @ValidateWithMethod(methodName="bar", parameterType=String.class, ignoreIfNull=true, message="BarError")
      })
      private String thing;