#Issue related to serde's flatten. Is it because of serde or ron?

5 messages · Page 1 of 1 (latest)

iron osprey
#

I noticed that when using #[serde(flatten)] and serializing to RON, I'm not able to deserialize the resulting RON . It's also worth noting, that it changed the outer struct's RON representation from a struct to a map.

So now I'm wondering where to report this issue. Is it a problem with the ron or serde crate? Or maybe I'm using it wrong somehow?

Here is an example of the issue:

#[derive(Debug, serde::Serialize, serde::Deserialize, PartialEq)]
struct Foo {
    a: String,
    #[serde(flatten)] // No errors without this
    bar: Bar,
}

#[derive(Debug, serde::Serialize, serde::Deserialize, PartialEq)]
struct Bar {
    b: String,
}

fn main() {
    let original = Foo {
        a: "1".into(),
        bar: Bar {
            b: "2".into()
        }
    };

    let ser = ron::ser::to_string(&original).unwrap();
    println!("{ser}\n");

    let de: Foo = ron::de::from_str(&ser).expect("deserialize");
    println!("{de:?}");

    assert_eq!(original, de);
}
turbid spear
#

it's a general problem with serde(flatten)

#

a very old one at that

iron osprey
#

I suppose that means it's unlikely to get fixed any time soon huh