Add (de-)serialization of set objects in sessions

This commit is contained in:
Guewen Baconnier
2020-05-11 07:35:05 +02:00
parent 35fb727d6c
commit ac89e923d7
+4
View File
@@ -19,6 +19,8 @@ class SessionEncoder(json.JSONEncoder):
return {"_type": "datetime_isoformat", "value": obj.isoformat()}
elif isinstance(obj, date):
return {"_type": "date_isoformat", "value": obj.isoformat()}
elif isinstance(obj, set):
return {"_type": "set", "value": tuple(obj)}
return json.JSONEncoder.default(self, obj)
@@ -36,4 +38,6 @@ class SessionDecoder(json.JSONDecoder):
return dateutil.parser.parse(obj["value"])
elif type_ == "date_isoformat":
return dateutil.parser.parse(obj["value"]).date()
elif type_ == "set":
return set(obj["value"])
return obj