From ac89e923d782f99a13932a0d0ea7b17fcf35dfa2 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 11 May 2020 07:35:05 +0200 Subject: [PATCH] Add (de-)serialization of set objects in sessions --- session_redis/json_encoding.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/session_redis/json_encoding.py b/session_redis/json_encoding.py index 88d8bcd..f535a8f 100644 --- a/session_redis/json_encoding.py +++ b/session_redis/json_encoding.py @@ -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