Both the Child and Parent classes inherit from Python dictionary:
import json
class Child(dict):
def __init__(self, **kwargs):
super(Child, self).__init__(**kwargs)
class Parent(dict):
def __init__(self, **kwargs):
super(Parent, self).__init__(**kwargs)
parent = Parent(child = Child())
print type(parent['child'])
prints:
<class '__main__.Child'>
After performing the serialization and de-serialization using json.dumps and json.loads the Parent['child'] becomes a regular dictionary:
dumped = json.dumps(parent)
loaded = json.loads(dumped)
parent_2 = Parent(**loaded)
print type(parent_2['child'])
prints:
<type 'dict'>
Question: how to make sure that after the serialization, the parent_2['child'] is the instance of the Child and not a regular Python dictionary?