-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable custom type serialization in JSONDisk
#285
Comments
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. |
That sounds good as well. But if generalizing it this way, it would be nice to define:
i.e. dumps method to return |
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: