def decode_json_object(data: dict) -> Do: m = Map(data) tpe_s = yield m.lift(tpe_key).to_either( f'no `{tpe_key}` attr in json object {m}') tpe = yield Either.import_path(tpe_s) dec = yield Decoder.e(tpe) yield dec.decode(tpe, m)
def decode(self, tpe: Type[Sub], data: JsonObject) -> Do: sub_json = yield data.field(tpe_key) sub = yield sub_json.as_scalar sub_type = yield Either.import_path(sub.native) yield decode_dat(sub_type, data)
def decode_json_object(data: dict) -> Generator: m = Map(data) tpe_s = yield m.get('__type__').to_either(f'no `__type__` attr in json object {m}') tpe = yield Either.import_path(tpe_s) dec = yield Decoder.e(tpe) yield dec.decode(tpe, m)