I can't find a proper solution to build an object with the nested classes from the parsed json. I would like to keep current init-methods (without the def __init__(self, **entries) -> self.__dict__.update(entries)) together with the __dict__ in the objects (example with the namedtuple does not work for me).
Example of the structure:
class C(object):
def __init__(self, name: str):
self.name = name
class B(object):
def __init__(self, name: str, c: Dict[str, C]):
self.name = name
self.c = c
class A(object):
def __init__(self, name: str, b: List[B]):
self.name = name
self.b = b
So I'm receiving an object data 'A' as json:
dump = json.dumps(data, default=lambda o: o.__dict__)
object_a = A(**json.loads(r))
Then if I check the types:
print(type(object_a))
print(type(object_a.b))
print(type(object_a.b[0]))
<class 'A'> <- ok
<class 'list'> <- ok
<class 'dict'> <- expected type 'B'
There is dict instead of the inner object B.
As far as I can see this question is not new. Isn't there a proper and simple way to obtain an object that you need?