You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently in JSONDisk, json.loads and json.dumps are used for keys/values (de-)serialization (with the stdlib json module). Both the json module and arguments to load/dump are hard-coded, making it hard to (de-)serialize custom/user types, like NumPy types, Pydantic models, even Python builtins like set or datetime.
To implement custom JSON serialization, one needs to practically rewrite JSONDisk class. While, instead, providing json.JSONEncoder/json.JSONDecoder subclassed would be a lot easier.
I'm imagining new JSONDisk arguments, json_encoder and json_decoder that could be provided by the user on instantiation and then used during (de-)serialization.
The text was updated successfully, but these errors were encountered:
I would rather not add more arguments. What about changing references like “json.loads” into instance attributes like “self.json_loads” and making “json_loads = json.loads” as a class attribute. Then you can inherit and assign those attributes as you like.
i.e. dumps method to return bytes instead of str that needs to be encoded.
That's because some libraries, like orjson, return already byte-encoded JSON.
Currently in
JSONDisk
,json.loads
andjson.dumps
are used for keys/values (de-)serialization (with the stdlibjson
module). Both thejson
module and arguments to load/dump are hard-coded, making it hard to (de-)serialize custom/user types, like NumPy types, Pydantic models, even Python builtins likeset
ordatetime
.To implement custom JSON serialization, one needs to practically rewrite
JSONDisk
class. While, instead, providingjson.JSONEncoder
/json.JSONDecoder
subclassed would be a lot easier.I'm imagining new
JSONDisk
arguments,json_encoder
andjson_decoder
that could be provided by the user on instantiation and then used during (de-)serialization.The text was updated successfully, but these errors were encountered: