python-a2s icon indicating copy to clipboard operation
python-a2s copied to clipboard

Fix #57

Open Bluscream opened this issue 1 year ago • 1 comments


    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)

Bluscream avatar Aug 25 '24 23:08 Bluscream

You removed the comments and added invalid typing. I am not accepting this.

Yepoleb avatar Aug 28 '24 02:08 Yepoleb

Dataclasses have been implemented in e40488b88b32f6ccb3a974bc5dbd5da777f3ff83

Yepoleb avatar Nov 02 '24 02:11 Yepoleb