python-a2s
python-a2s copied to clipboard
Fix #57
def toDict(self, obj):
return json.loads(json.dumps(obj, cls=CustomJSONEncoder))
class CustomJSONEncoder(json.JSONEncoder): # <<-- Add this custom encoder
"""Custom JSON encoder for the DB class."""
def default(self, o):
if dataclasses.is_dataclass(o): # this serializes anything dataclass can handle
return dataclasses.asdict(o)
if isinstance(o, datetime): # this adds support for datetime
return o.isoformat()
return super().default(o)
You removed the comments and added invalid typing. I am not accepting this.
Dataclasses have been implemented in e40488b88b32f6ccb3a974bc5dbd5da777f3ff83