craftbeerpi4-pione/core/utils/encoder.py

24 lines
595 B
Python
Raw Normal View History

2018-11-18 15:40:10 +01:00
from json import JSONEncoder
class ComplexEncoder(JSONEncoder):
def default(self, obj):
from core.database.orm_framework import DBModel
2018-12-29 00:27:19 +01:00
2018-11-18 15:40:10 +01:00
try:
if isinstance(obj, DBModel):
return obj.__dict__
2018-12-29 00:27:19 +01:00
#elif callable(getattr(obj, "reprJSON")):
# return obj.reprJSON()
2018-12-13 21:45:33 +01:00
#elif isinstance(obj, ActorModel):
# return None
2019-01-02 21:20:44 +01:00
#elif hasattr(obj, "callback"):
# return obj()
2018-11-18 15:40:10 +01:00
else:
return None
2019-01-02 21:20:44 +01:00
except TypeError:
2018-11-18 15:40:10 +01:00
pass
return None