Example #1
0
        def default(self, o: t.Any) -> t.Any:  # pylint: disable=method-hidden
            """A way to serialize arbitrary methods to JSON.

            Classes can use this method by implementing a `__to_json__` method
            that should return a JSON serializable object.

            :param o: The object that should be converted to JSON.
            """
            if hasattr(o, '__extended_to_json__') and use_extended(o):
                return o.__extended_to_json__()
            else:
                return super().default(o)
Example #2
0
        def default(self, obj: t.Any) -> t.Any:  # pylint: disable=E0202,arguments-differ
            """A way to serialize arbitrary methods to JSON.

            Classes can use this method by implementing a `__to_json__` method
            that should return a JSON serializable object.

            :param object obj: The object that should be converted to JSON.
            """
            if hasattr(obj, '__extended_to_json__') and use_extended(obj):
                try:
                    return obj.__extended_to_json__()
                except AttributeError:  # pragma: no cover
                    pass

            try:
                return obj.__to_json__()
            except AttributeError:  # pragma: no cover
                return super().default(obj)