Closed vlcinsky closed 2 years ago
Sounds intresting and I can see myself using this, I definitely needed something like that in the past, but I am not so sure how it fits in the xml & json bindings context, it could be a completely unrelated library that can print valid python code from any python object or dataclass.
A code, which would process any python object or dataclass into valid python code would be very straightforward and great. But I am not sure it is as simple as it sounds. I would expect it would be as complex as pickling or as deepcopy code. I will be happy if anyone proves me wrong.
With PycodeSerializer we would give all the control to the author of given library creating the classes used to represent input (XML or JSON) data.
I would gladly accept any contributions on the subject, but it's really not a top priority for a binding library...
Re-opening this one
Hi @vlcinsky I know it's been a while, but the first version is now on master, give it a try
@tefra excellent.
My first tests show, that the code looks good, it has only one issue with the lang
parameter.
I assume the reason could be, that the lang
is defined on XML level itself and not as part of XSD. If I comment the lang
parameter out, things work well.
I will create a tests case for it.
@tefra excellent.
My first tests show, that the code looks good, it has only one issue with the
lang
parameter.I assume the reason could be, that the
lang
is defined on XML level itself and not as part of XSD. If I comment thelang
parameter out, things work well.I will create a tests case for it.
Can you open a new issue with an example? I can take a look
Detailed instructions to reproduce the error are in #697
Motivation
We maintain set of XML samples conforming to specific XML schema.
We are considering to generate these samples by python code using xsdata and xsdata generated package.
It would be helpful to have an option to generate the python representation by converting XML samples into it.
Context
The python package allowing to build XML objects depends on XML schema and on backing object library:
If we load an XML sample into xsdata based objects, we may:
Proposed approach - pycode serializer
Currently, we use XmlSerializer
If the backing library provides PycodeSerializer, we can get the python code generated.
Such a serializer would be optional (so new backing libraries would not be obliged to provide that).
To get the python code, one would find in documentation example similar to https://xsdata.readthedocs.io/en/latest/json.html#serialize-json-to-string or we could even add section Python code binding, which would not only serialize.
The code would be similar to:
and the generated python code would be: