BurntSushi / BurntSushi/rust-csv

serializing nested struct with #[serde(flatten)] is not supported

Open
#239 18 comments 11 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
2k
Forks
257
PR merge metrics
No merged PRs in 30d

Description

#### What version of the `csv` crate are you using?

version = "1.1.6"

#### Briefly describe the question, bug or feature request.

The program panics when serializing a struct that contains a nested struct decorated by #[serde(flatten)].
I am not sure whether this is a bug or expected behavior but I would expect the program to output a csv.
If it is expected are there any alternatives to obtain the desired output (without removing nesting) ?

#### Include a complete program demonstrating a problem.

```rust
use serde::Serialize;

fn main() {
let mut w = csv::Writer::from_writer(std::io::stdout());
w.serialize(Message::default()).unwrap();
}

#[derive(Serialize, Default)]
struct Message {
content: String,
#[serde(flatten)]
to: Person,
}

#[derive(Serialize, Default)]
struct Person {
name: String,
}
```

#### What is the observed behavior of the code above?
```bash
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error(Serialize("serializing maps is not supported, if you have a use case, please file an issue at https://github.com/BurntSushi/rust-csv"))', src/main.rs:5:37
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

#### What is the expected or desired behavior of the code above?
```csv
content,name
,
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.