I have a list of account types defined as enumerations in a web services implementation. However, when the consumer call web service passes a string that must be converted to an enumeration.
What is a good way to verify that a given string will be successfully converted to an enumeration?
I used the following approach, but this is probably an abuse of exceptions (according to Effective Java, paragraph 57).
AccountType accountType = null;
try{
accountType = AccountType.valueOf(accountTypeString);
}catch(IllegalArgumentException e){
}
if (accountType != null){
}else{
}
source
share