def decode(self, to_decode_as_str: str, *args, **kwargs) -> object: to_decode_as_dict = json.loads(to_decode_as_str) simple_model = SimpleModel() simple_model.a = to_decode_as_dict["serialized_a"] simple_model.b = to_decode_as_dict["serialized_b"] return simple_model
def create_simple_model_with_json_representation(modifier: int=0) -> Tuple[SimpleModel, Dict]: """ Creates an instance of `SimpleModel` alongside its expected JSON representation (given the most obvious property mappings). :param modifier: can be used to make the model distinguishable :return: tuple where the first value is the model and the second is its JSON representation """ simple_model = SimpleModel(50) simple_model.a = modifier simple_model_as_json = { "serialized_a": simple_model.a, "serialized_b": simple_model.b } return simple_model, simple_model_as_json