I have a list of accounts types defined as enums in the web services implementation. However, when consumer call web service it passes a String that needs to be converted to enum.
What is a good way to validate that given String will be successfully converted to enum?
I was using the following approach, but this is probably an abuse of exceptions (according to Effective Java, item 57).
AccountType accountType = null;
try{
accountType = AccountType.valueOf(accountTypeString);
}catch(IllegalArgumentException e){
// report error
}
if (accountType != null){
// do stuff
}else{
// exit
}