Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save baberali/f61a3293746b499da6b5e8d27838b2da to your computer and use it in GitHub Desktop.
Save baberali/f61a3293746b499da6b5e8d27838b2da to your computer and use it in GitHub Desktop.
Get control and handle error condition with custom exception when spring/jackson is unable to parse invalid Enum value
// put this method in the enum
// it will be called by jackson when mapping a value to enum
@JsonCreator
public static EnumType fromString(String string) {
EnumType enumType = null;
try {
enumType = EnumType.valueOf(string);
} catch (Exception e) {
new MyRuntimeException(string);
}
return enumType;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment