jplatte / serde_html_form

Rust crate for (de-)serialization of `application/x-www-form-urlencoded` data.
MIT License
23 stars 3 forks source link

This does not work with `#[serde(flatten)` #18

Closed vnghia closed 7 months ago

vnghia commented 7 months ago

Hello,

Thank you for your crate. I found one bug here.

#[derive(Deserialize, Debug, PartialEq)]
struct InnerType {
    pub a: Option<u32>,
}

#[derive(Deserialize, Debug, PartialEq)]
struct OuterType {
    #[serde(flatten)]
    pub inner: InnerType,
}

#[test]
fn deserialize_flatten() {
    let params = OuterType { inner: InnerType { a: Some(10) } };
    assert_eq!(super::from_str("a=10"), Ok(params));
}

this code failed with Error("invalid type: string \"10\", expected u32"). It seems that other features do not work as well.

jplatte commented 7 months ago

Hi! I'm afraid this is an instance of https://github.com/serde-rs/serde/issues/1183 and not something this library can fix. My recommendation is to avoid serde(flatten) if you can.