-
-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
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
nillable fields are skipped by XmlSerializer #408
Comments
Initialize the field with an empty string. order = Shiporder()
order.name = ""
xml = xml_serializer.render(order)
print(xml) <?xml version="1.0" encoding="UTF-8"?>
<shiporder>
<name xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</shiporder That's the parser's behavior as well obj = XmlParser().from_string(xml, Shiporder)
print(obj)
# Shiporder(name='') It seems a bit weird I agree and I can't really remember right now why I had to do it this way, I am going to take another look again. |
I took out this behavior and run the w3c test suite, everything passed as expected, I still can't remember why I had to do that. Thanks for reporting @barsv |
Thank you! The empty string works good for me. I want to add for others who might find this issue ticket in the future that the same workaround works for XmlDateTime as well. I don't know if the issue should be closed though because the field type in the data class is |
No leave it open I am planning to change this behavior in the next release, to avoid the empty string hack I just need to test a few more things |
Thank you for reporting @barsv the fix is on master and will be included in the next release. |
Hi,
I have nillable="true" in my xsd. I generated a python class for this xsd. I serialize the class into xml using XmlSerializer. My problem is that the nillable field is missing in the xml.
I have
in the generated code for the nillable field. So I think that XmlSerializer should generate an empty tag for this field.
I don't know if it's a bug or not. Could you please suggest.
More details:
I created a small repo to reproduce: https://github.com/barsv/xsdata-issue.git
My test.xsd file:
I generated test.py using
xsdata test.xsd
:I serialize it using the following code:
and I get the following xml:
This xml doesn't pass validation against the original xsd.
I would expect to get the following xml instead:
ps: I'm not an expert in neither xsd nor python.
The text was updated successfully, but these errors were encountered: