Skip to content

Add alias_all attribute for containers similar to rename_all #1530

@dmarcuse

Description

@dmarcuse

The rename_all attribute is very handy for cases where you have fields named in ways that don't follow Rust conventions. However, there are cases where you might want to support both ways - for example, loading data with support for both naming conventions, but preferring a different naming convention for saving that data later. I propose that an alias_all container attribute be added that functions similarly to rename_all, so that a struct like this...

#[derive(Serialize, Deserialize)]
#[serde(alias_all = "PascalCase")]
pub struct MyStruct {
    string: String,
    bool: bool
}

...can be deserialized from JSON like this...

{"String":"hello world","Bool":true}

...but will still be serialized like this:

{"string":"hello world","bool":true}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions