Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicated field in output #1074

Open
DevSlashRichie opened this issue Oct 5, 2023 · 0 comments
Open

Duplicated field in output #1074

DevSlashRichie opened this issue Oct 5, 2023 · 0 comments

Comments

@DevSlashRichie
Copy link

DevSlashRichie commented Oct 5, 2023

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"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant