Properly use xsi:nil to deserialize null values via serde#850
Merged
Mingun merged 8 commits intotafia:masterfrom Mar 25, 2025
Merged
Properly use xsi:nil to deserialize null values via serde#850Mingun merged 8 commits intotafia:masterfrom
Mingun merged 8 commits intotafia:masterfrom
Conversation
This affects performance of the serde deserializer by ~20%, unfortunately
failures (11):
as_field::empty::nested::true_
as_field::with_attr::nested::true_
as_field::with_element::nested::true_
as_field::with_element::ns0::true_
as_field::with_element::xsi::true_
top_level_option::empty::ns0::true_
top_level_option::empty::xsi::true_
top_level_option::with_attr::ns0::true_
top_level_option::with_attr::xsi::true_
top_level_option::with_element::ns0::true_
top_level_option::with_element::xsi::true_
This commit fixes an issue that causes `quick-xml` trying to deserialize
empty tags via the serde interface even if these tags were explicitly
marked as `xsi:nil="true"`
For example the following XML failed to deserialize before this commit:
```xml
<bar>
<foo xsi:nil="true"/>
</bar>
```
into the following rust type:
```rust
#[derive(Deserialize)]
struct Bar {
foo: Option<Foo>,
}
#[derive(Deserialize)]
struct Foo {
baz: String,
}
```
Before this commit this failed to deserialize with an error message that
complained that the `baz` field was missing. After this commit this uses
the `xsi:nil` attribute to deserialize this into `foo: None` instead.
The standard (https://www.w3.org/TR/xmlschema-1/#xsi_nil) seems to
support this behaviour.
Fix tafia#497
406b2d0 to
3c4de88
Compare
|
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #850 +/- ##
==========================================
+ Coverage 60.21% 60.47% +0.26%
==========================================
Files 41 41
Lines 16021 16112 +91
==========================================
+ Hits 9647 9744 +97
+ Misses 6374 6368 -6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
dralley
approved these changes
Mar 24, 2025
This was referenced Mar 25, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #842 because I cannot push to it directly.
@weiznich, thanks for your contribution! I finally found the time to finish and polish your work. If you have anything to say about the proposed mapping scheme, feel free to.
Here is the benchmark results of
comparesubproject between master (c8fe850) and namespace-aware deserializer (b8ce862):criterion-namespace-aware-deserializer.zip