Here's my situation,
I have a class with Enum type fields. I want to execute annotated validation for enum types, similar to annotations for strings, example: @Size, @NotNull etc.
Problem is, json deserializer fails on enum type before validation occurs.
public class myClass {
@JsonProperty
//@SomeCustomValidator -- ??
private EnumType enumValue;
}
public enum EnumType {
A,
B,
C
}
Few things:
- I do not want to change the data type to
String. Tried steps in following threads, didn't fix my problem.
Tried this link, but get an error in deserialization before validation hits
Validation works after the type of the argument is resolved. So I don't see a way how to use String validating annotations on enums. As workaround you can use @JsonCreator and do some validation before object creation.