Created
May 9, 2017 06:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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