craftbeerpi4-pione/cbpi/utils/encoder.py
2019-07-27 21:08:19 +02:00

16 lines
365 B
Python

from json import JSONEncoder
class ComplexEncoder(JSONEncoder):
def default(self, obj):
try:
if hasattr(obj, "to_json") and callable(getattr(obj, "to_json")):
return obj.to_json()
else:
raise TypeError()
except Exception as e:
print(e)
pass
return None