dtolnay/serde-yaml

#[serde(flatten)] disables treating an integer as a string

Opened this issue · 0 comments

In the following example the first struct deserializes , but the second one fails with "invalid type: integer 42, expected a string".

use serde::Deserialize;

#[derive(Deserialize)]
struct Inner {
    x: String,
}

#[derive(Deserialize)]
struct S {
    #[serde(flatten)]
    inner: Inner,
}

fn main() {
    let t = "x: 42";
    let v: Inner = serde_yaml::from_str(t).unwrap();
    println!("{}", v.x);

    let v: S = serde_yaml::from_str(t).unwrap();
    println!("{}", v.inner.x);
}