1

I want to add all available values of an enum to a hibernate validation message. But I can't, as it expects a constant expression.

@NotNull(message = "Allowed values: " + MyEnum.values());

Result error:

The value for annotation attribute NotNull.message must be a constant expression

How can this be done?

membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • http://stackoverflow.com/questions/13253624/how-to-supply-enum-value-to-an-annotation-from-a-constant-in-java#answer-13253879 – cy3er Oct 31 '14 at 11:57
  • You can not, but you can create a custom constraint to validate against MyEnum values. – vzamanillo Nov 03 '14 at 16:24

1 Answers1

1

I don't think this can be done. See also Use Enum type as a value parameter for @RolesAllowed-Annotation.

Basically a compile-time constant expressions needs to be passed to message. See also JSL section.

Community
  • 1
  • 1
Hardy
  • 18,659
  • 3
  • 49
  • 65