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

Global configuration #1086

Open
ogesaku opened this issue Nov 25, 2023 · 0 comments
Open

Global configuration #1086

ogesaku opened this issue Nov 25, 2023 · 0 comments

Comments

@ogesaku
Copy link

ogesaku commented Nov 25, 2023

Hey, I would like to apply the same formatting to all json responses: camelCase, timeFormat and no empty options. Example:

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct Person {
    pub first_name: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bio: Option<String>,
    #[serde(with = "my_date_format")]
    pub birthday: DateTime<Utc>,
}

Is there an option to do it globally for all serialized structs?

I tried implementing a custom serializer like in #833 and https://serde.rs/impl-serializer.html, but could not find a way to apply the conditions.

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