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

Boolean fields specified with integers always parse as true #41

Closed
csssuf opened this issue Aug 30, 2017 · 2 comments
Closed

Boolean fields specified with integers always parse as true #41

csssuf opened this issue Aug 30, 2017 · 2 comments
Labels

Comments

@csssuf
Copy link

csssuf commented Aug 30, 2017

Boolean fields specified as integers always seem to parse as true, even with contents of 0:

#[macro_use] extern crate serde_derive;
extern crate serde_xml_rs;

#[derive(Debug, Deserialize)]
struct Structure {
    boolean_field: bool,
}

fn main() {
    let s = r##"
        <Structure boolean_field="0">
        </Structure>
    "##;
    let test: Structure = serde_xml_rs::from_reader(s.as_bytes()).unwrap();
    println!("{:#?}", test);
}

This test program outputs:

Structure {
    boolean_field: true
}
@oli-obk oli-obk added the bug label Aug 30, 2017
@RReverser
Copy link
Owner

This seems to be a duplicate of #18, please see my reasoning there.

@oli-obk oli-obk added wontfix and removed bug labels Aug 30, 2017
@oli-obk
Copy link
Collaborator

oli-obk commented Aug 30, 2017

Note that you can always use #[serde(deserialize_with=foo)] to overwrite the behaviour to match your use case. (See https://serde.rs/field-attrs.html for details on how to do that)

@oli-obk oli-obk closed this as completed Aug 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants