def map_get_value_cast(map, key, cast_type=str, default_value=None):
    """
    Retrieves the value of the map for the given key.
    The value is casted to the given type.
    In case something wrong (exception raised) occurs
    the default value is returned.

    :type map: Dictionary
    :param map: The dictionary to be used.
    :type key: String
    :param key: The key to the value to be retrieved.
    :type cast_type: Type
    :param cast_type: The type to be used to cast the retrieved
    value (this should be a valid type, with constructor).
    :type default_value: Object
    :param default_value: The default value to be used
    when something wrong (exception raised) occurs.
    :rtype: Object
    :return: The retrieved value casted to the defined type.
    """
    try:
        value = map[key]
        value_type = type(value)
        if value_type == cast_type:
            value_casted = value
        else:
            value_casted = cast_type(value)
        return value_casted
    except Exception:
        return default_value
