I have some JSON data I want to deserialize that looks similar to
{
"a" : {
"b": {
ACTUAL DATA
}
}
}
In my case, object "a" has only one member, object "b", which in turns contains all of the data. I am able to deserialize this using two structures
#[derive(Serialize, Deserialize)]
struct A {
#[serde(rename = "a")]
b: B,
}
#[derive(Serialize, Deserialize)]
struct B {
#[serde(rename = "b")]
data: REAL_DATA,
}
But it doesn't feel very elegant. I don't want to ever use or interact with struct B, and I would much rather be able to deserialize the data directly into one struct, maybe using something like #[serde(rename="a.b")]
. I found someone mentioning the same issue at Flatten · Issue #119 · serde-rs/serde · GitHub, but this is from 2016 and there didn't seem to be a conclusion to this particular comment. Is there a built in solution to this problem that has been created in the intervening years, or are workarounds still the way to go?