@ SuppressWarnings ( "unchecked" ) public Object unmarshal ( Object obj ) throws RpcException { if ( obj == null ) { return returnNullIfOptional ( ) ; } else if ( obj . getClass ( ) != String . class ) { String msg = "'" + obj + "' enum must be String, got: " + obj . getClass ( ) . getSimpleName ( ) ; throw RpcException . Error . INVALID_PARAMS . exc ( msg ) ; } else if ( e . getValues ( ) . contains ( ( String ) obj ) ) { try { Class clz = getTypeClass ( ) ; return java . lang . Enum . valueOf ( clz , ( String ) obj ) ; } catch ( Exception e ) { String msg = "Could not set enum value '" + obj + "' - " + e . getClass ( ) . getSimpleName ( ) + " - " + e . getMessage ( ) ; throw RpcException . Error . INTERNAL . exc ( msg ) ; } } else { String msg = "'" + obj + "' is not in enum: " + e . getValues ( ) ; throw RpcException . Error . INVALID_PARAMS . exc ( msg ) ; } }
Enforces that obj is a String contained in the Enum s values list