def json_encoder_to_serializer(encoder_cls: Union[Type[JSONEncoder], Callable[[], Type[JSONEncoder]]]) \
        -> Type[Serializer]:
    """
    Converts a `JSONEncoder` class into an equivalent `Serializer` class.
    :param encoder_cls: the encoder class type or a function that returns the type
    :return: the equivalent `Serializer` class
    """
    name = encoder_cls.__name__ if isinstance(encoder_cls, type) else "%sLambdaTypeReturn" % id(encoder_cls)
    return type(
        "%sAsSerializer" % name,
        (_JSONEncoderAsSerializer,),
        {
            "encoder_type": property(lambda self: encoder_cls if isinstance(encoder_cls, type) else encoder_cls())
        }
    )