You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to serialize a struct containing other structs to CSV, which is why I use flatten.
However some of these structs have fields with the same name, which make the output unpractical to read.
I would like to prefix the flattened fields to be able to distinguish them.
Minimal example
use serde::Serialize;fnmain(){let json = serde_json::to_string(&Message::default()).unwrap();println!("{}", json);}#[derive(Serialize,Default)]structMessage{content:String,#[serde(flatten)]// put new feature herefrom:Person,#[serde(flatten)]// put new feature hereto:Person,}#[derive(Serialize,Default)]structPerson{name:String,}
Output
{"content":"","name":"","name":""}
Wanted Output example
{"content":"","from.name":"","to.name":""}
Maybe this could be implemented as an option on the flatten macro, or as an extension on the renaming macro ?
The text was updated successfully, but these errors were encountered:
serde_with::with_prefix!(prefix_from "from.");
serde_with::with_prefix!(prefix_to "to.");#[derive(Serialize,Default)]structMessage{content:String,#[serde(flatten, with = "prefix_from")]from:Person,#[serde(flatten, with = "prefix_to")]to:Person,}
However, IIRC, the csv crate does not support structs which use flatten internally.
Usecase
I want to serialize a struct containing other structs to CSV, which is why I use flatten.
However some of these structs have fields with the same name, which make the output unpractical to read.
I would like to prefix the flattened fields to be able to distinguish them.
Minimal example
Output
Wanted Output example
Maybe this could be implemented as an option on the flatten macro, or as an extension on the renaming macro ?
The text was updated successfully, but these errors were encountered: