Add parsing and test of nested arrays (objs with get_dict)
Idea: generic to_dict where all objects inherit from some base "serialisable" that has some base get_dict method with:
@staticmethod
def serialize(obj):
if isinstance(v, str) or isinstance(v, int) or isinstance(v, float) or isinstance(v, bool):
return v
if isinstance(v, list):
return [serialize(x) for x in v]
if isinstance(v, dict):
return {k: serialize(v) for k,v in v.items() if v is not None}
if callable(getattr(v, "get_dict", None)):
return v.get_dict()
raise Exception(f"Can't serialize '{type(obj)}'")
def get_dict(self):
return {k:serialize(v) for k,v in vars(self).items if v is not None)
Add parsing and test of nested arrays (objs with get_dict)
Idea: generic to_dict where all objects inherit from some base "serialisable" that has some base get_dict method with: