def METHOD_NAME(self, val):
    if isinstance(val, datetime):
        return format_iso8601(val)
    elif isinstance(val, Enum):
        return val.name
    elif hasattr(val, "to_json") and callable(val.to_json):
        return val.to_json()
    return json.JSONEncoder.METHOD_NAME(self, val)  # pragma: no cover