Skip to content
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

None values serialize as empty element and fail round trip deserializing #636

Closed
hfiguiere opened this issue Aug 20, 2023 · 2 comments
Closed
Labels
serde Issues related to mapping from Rust types to XML

Comments

@hfiguiere
Copy link

hfiguiere commented Aug 20, 2023

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(rename = "results")]
pub struct Results {
    #[serde(default)]
    pub raw_type_id: Option<u32>,
}

let r = Results { raw_type_id: None };

Serializing r will output:

<results>
<raw_type_id />
</results>

Deserializing the xml will fail with:

thread 'tests::deser' panicked at 'deserialize: InvalidInt(ParseIntError { kind: Empty })', src/lib.rs:133:45

So round trip serialization fails.

However

<results>
</results>

Will be sucessful and equal to

Results { raw_type_id: None }

Note: serde_xml_rs has similar issues.

I have two expectations here:

  1. that None value be allowed to not generate an empty element. This would work around the serialization error.
  2. the an empty element desrialization works for the underlying type is Option<> and then yield None.

Unless I'm misunderstanding how this is supposed to work, but round trip defintely fails.

@hfiguiere hfiguiere changed the title None values serialize as empty element and fail reserializing None values serialize as empty element and fail rount trip deserializing Aug 20, 2023
@hfiguiere hfiguiere changed the title None values serialize as empty element and fail rount trip deserializing None values serialize as empty element and fail round trip deserializing Aug 20, 2023
@hfiguiere
Copy link
Author

Probably the same as #497

@Mingun
Copy link
Collaborator

Mingun commented Aug 20, 2023

Yes, this is duplicate of #497

@Mingun Mingun closed this as not planned Won't fix, can't repro, duplicate, stale Aug 20, 2023
@Mingun Mingun added the serde Issues related to mapping from Rust types to XML label Aug 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

No branches or pull requests

2 participants