rust serde - flatten path on deserialize

Viewed 651

I want to deserialize a pretty deep JSON to Rust struct:

{
  "root": {
    "f1": {
      "f2": {
         "f3": 123
       }
    }
  }
}

When deriving Deserialize, I will have to create too many structs - one for each level for the above JSON :

struct Root {
  f1: Field1
}
struct Field1 {
  f2: Field2
}
struct Field3 {
  f3: Field3
}
// ...

Is there any way to avoid having this number of structs. I didn't find any attribute, which could be helpful with derive. I would like to have something like:

struct Root {
  // some attr?
  f3: u64
}

For sure, it is possible to implementing custom deserialize, but I wonder, whether there is a default way to achieve this.

0 Answers
Related