public static Enum castToEnum(Object object,Class<? extends Enum> type){
  if (object == null)   return null;
  if (type.isInstance(object))   return (Enum)object;
  if (object instanceof String || object instanceof GString) {
    return Enum.valueOf(type,object.toString());
  }
  throw new GroovyCastException(object,type);
}

public static Enum castToEnum ( Object object , Class < ? extends Enum > type ) { if ( object == null ) return null ; if ( type . isInstance ( object ) ) return ( Enum ) object ; if ( object instanceof String || object instanceof GString ) { return Enum . valueOf ( type , object . toString ( ) ) ; } throw new GroovyCastException ( object , type ) ; }
this class requires that the supplied enum is not fitting a collection case for casting
