structdiff icon indicating copy to clipboard operation
structdiff copied to clipboard

serde compatibility

Open carlocorradini opened this issue 7 months ago • 0 comments

serde compatibility could be extremely useful (like with ts_rs). The 'Difference' macro should recognize some serde attributes (such as rename or rename_all) and add them to the resulting difference enum.

#[derive(Serialize, Deserialize, Difference)]
#[serde(rename_all(serialize = "camelCase"))]
#[difference(expose = "ExampleDiff")]
struct Example {
    pub id: String,
    pub date_of_birthday: String,    // dateOfBirthday
    #[serde(rename = "updatedAt")]
    pub update: String,              // updatedAt
}

Given the previous example, the resulting ExampleDiff enum should have the attribute #[serde(rename_all(serialize = "camelCase"))] and its update variant the attribute #[serde(rename = "updatedAt")]. This ensures that the Example struct and ExampleDiff enum are in sync with their ser(de) counterparts.

carlocorradini avatar Jul 03 '25 12:07 carlocorradini