1

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?

George Mauer
  • 117,483
  • 131
  • 382
  • 612

2 Answers2

4

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;
Brian Ensink
  • 11,092
  • 3
  • 50
  • 63
2

You can use the @ValidateWithMethod.List annotation to declare multiple @ValidateWithMethod on the same element.

Marek Grzenkowicz
  • 17,024
  • 9
  • 81
  • 111
Georg
  • 21
  • 2