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
Hi,
I have a problem where I'm trying to deserialize nested objects, and have each of their respective load functions trigger.
Code example:
from typing import List
import jsons
class B(jsons.JsonSerializable):
c: List[str]
@classmethod
def load(cls, json_obj, **kwargs):
print("Loading", cls)
return jsons.load(json_obj, cls, **kwargs)
class A(jsons.JsonSerializable):
b: B
@classmethod
def load(cls, json_obj, **kwargs):
print("Loading", cls)
return jsons.load(json_obj, cls, **kwargs)
obj = {'b': {'c': ['d', 'd']}}
jsons.load(obj, A) # Nothing printed
A.load(obj) # Only "Loading <class '__main__.A'>" is printed
What I would expect as default behavior in this case is to have both Loading <class ...B> and Loading <class ...A> printed.
Is there any way to achieve this behavior?
Thanks!
The text was updated successfully, but these errors were encountered:
After I've thought about it a little more, the problem is that jsons.load (and I guess also loads) doesn't check if the cls inherits from the jsons.JsonSerializable class, and if it does it should call its respective load / loads methods. Also for dumping I guess.
Hi,
I have a problem where I'm trying to deserialize nested objects, and have each of their respective
load
functions trigger.Code example:
What I would expect as default behavior in this case is to have both
Loading <class ...B>
andLoading <class ...A>
printed.Is there any way to achieve this behavior?
Thanks!
The text was updated successfully, but these errors were encountered: