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

Empty strings not correctly deserialized #178

Open
JonathanBrouwer opened this issue Feb 9, 2024 · 1 comment
Open

Empty strings not correctly deserialized #178

JonathanBrouwer opened this issue Feb 9, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@JonathanBrouwer
Copy link

JonathanBrouwer commented Feb 9, 2024

The following example fails:

#[derive(YaSerialize, YaDeserialize)]
pub struct Test {
    v: String
}

#[test]
fn test() {
    let v = Test {
        v: "".to_string()
    };

    yaserde::de::from_str::<Test>(&dbg!(yaserde::ser::to_string(&v).unwrap())).unwrap();
}

The struct is correctly serialized to:

<?xml version=\"1.0\" encoding=\"utf-8\"?><Test><v></v></Test>

The error message is "v is a required field of Test". The problem occurs because the visit_str function is not called since there is no string.

@MarcAntoine-Arnaud MarcAntoine-Arnaud added the bug Something isn't working label May 9, 2024
@MarcAntoine-Arnaud
Copy link
Contributor

In fact xml-rs does not handle event XmlEvent::Characters.

So only a StartElement and EndElement are emitted.

So specific code has to be done for that case, without breaking the rest :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants