JSON serializer for objects not serializable by default json code

def json_serial(cls, obj):
        """JSON serializer for objects not serializable by default json code"""

        if isinstance(obj, datetime):
            serial = obj.isoformat()

        elif issubclass(obj.__class__, enum.Enum):
            serial = obj.value

        elif isinstance(obj, timedelta):
            serial = str(obj)

        elif isinstance(obj, set):
            serial = list(x for x in obj)

        elif isinstance(obj, uuid.UUID):
            serial = str(obj)

        # FIXME: if you want to add one more custom serializer, think twice about `singledispatch`

        else:
            raise TypeError("Type not serializable %s in %s" % (type(obj), obj))

        return serial