json
json copied to clipboard
Duplicated field in output
When I use tag on a (flatten) enum, and add a field with the same name, on a struct serde will output a json with a duplicated field.
// struct
#[derive(Debug, Serialize, Deserialize)]
pub struct CreateEvent {
#[serde(rename = "type")]
ty: EventTypeDiscriminants,
from: NaiveDateTime,
to: NaiveDateTime,
#[serde(flatten)]
data: CreateEventType,
}
// CreateEventType
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type", content = "data")]
pub enum CreateEventType {
#[serde(rename = "field")]
Field,
#[serde(rename = "class")]
Class(CreateClass),
}
output
{
"type": "class",
"from": "1970-01-01T00:00:00",
"to": "1970-01-01T00:00:00",
"type": "class",
"data": {
"teacher_id": "usr_b7a7zAh6XlTeN4azMcCFL"
}
}