Skip to content

Properly use xsi:nil to deserialize null values via serde #850

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

Merged
merged 8 commits into from
Mar 25, 2025

Conversation

Mingun
Copy link
Collaborator

@Mingun Mingun commented Mar 21, 2025

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 compare subproject between master (c8fe850) and namespace-aware deserializer (b8ce862):
criterion-namespace-aware-deserializer.zip

weiznich and others added 6 commits March 16, 2025 17:19
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_
@Mingun Mingun added enhancement serde Issues related to mapping from Rust types to XML namespaces Issues related to namespaces support labels Mar 21, 2025
@Mingun Mingun requested a review from dralley March 21, 2025 16:28
weiznich and others added 2 commits March 21, 2025 21:34
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
@Mingun Mingun force-pushed the fix/honor_xsi_nil branch from 406b2d0 to 3c4de88 Compare March 21, 2025 16:40
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 46.77419% with 66 lines in your changes missing coverage. Please review.

Project coverage is 60.47%. Comparing base (a9391f3) to head (3c4de88).
Report is 27 commits behind head on master.

Files with missing lines Patch % Lines
src/de/mod.rs 38.63% 54 Missing ⚠️
src/events/attributes.rs 55.55% 12 Missing ⚠️

❗ 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     
Flag Coverage Δ
unittests 60.47% <46.77%> (+0.26%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Mingun Mingun merged commit 44644b3 into tafia:master Mar 25, 2025
7 checks passed
@Mingun Mingun deleted the fix/honor_xsi_nil branch March 25, 2025 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement namespaces Issues related to namespaces support serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants