Open 981377660LMT opened 1 month ago
import operator
from json import JSONEncoder, dumps
def _default(self, obj):
return getattr(obj.__class__, "to_json", _default.default)(obj)
_default.default = JSONEncoder().default
JSONEncoder.default = _default
class XXX:
def to_json(self):
return 1
monkey patch
https://stackoverflow.com/a/38764817