We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Currently I know only two workarounds. After explaining them I will ask my questions at the end ;-)
The first workarounds involves using json.loads and json.dumps:
json.loads
json.dumps
def model_to_dict(model): json_serializer = JsonSerializer() json_string = json_serializer.render(model) return json.loads(json_string) def dict_to_model(a_dict): json_string = json.dumps(a_dict) json_parser = JsonParser() return json_parser.parse(json_string, generated.Model)
This works but requires the extra step of creating a json string.
The second workaround exploits the fact that xsdata uses dicts internally.
For serialization this is kind of supported and documented:
def model_to_dict(model): result = {} def dict_dumper(obj, *_args, **_kwargs): result.update(obj) json_serializer = JsonSerializer(dump_factory=dict_dumper) json_serializer.write(None, model) return result
For parsing it exploits undocumented internals:
def dict_to_model(a_dict): class FakeSourceHavingReadAttribute: def read(self): pass def dict_loader(_src): return a_dict json_parser = JsonParser(load_factory=dict_loader) model = json_parser.parse(FakeSourceHavingReadAttribute(), generated.Model) return model
Two questions
JsonParser
FakeSourceHavingReadAttribute
The text was updated successfully, but these errors were encountered:
The parser exists but it's not documented, it needs some refactoring to follow the parser interface, the serializer is also planned.
They are on top of my priorities after I finish refactoring all the docstrings/documentation.
Sorry, something went wrong.
Add dict encoder/decoder
2317eba
Resolves #921
b93ccc1
Add dict encoder/decoder (#939)
1d4012e
I surfaced the dict parser as the dict decoder and extracted the dict encoder from the json serializer
Successfully merging a pull request may close this issue.
Allow serialization of dataclass objects from and to dict
Currently I know only two workarounds.
After explaining them I will ask my questions at the end ;-)
The first workarounds involves using
json.loads
andjson.dumps
:This works but requires the extra step of creating a json string.
The second workaround exploits the fact that xsdata uses dicts internally.
For serialization this is kind of supported and documented:
For parsing it exploits undocumented internals:
Two questions
JsonParser
to get rid of theFakeSourceHavingReadAttribute
hack?The text was updated successfully, but these errors were encountered: