evestera / json_typegen

Tools and libraries to create types for Rust, Kotlin, TypeScript and Python from JSON samples
https://typegen.vestera.as
Apache License 2.0
268 stars 26 forks source link

Rust | Add an option for snake_case to camelCase conversion on a per-struct basis instead of on a per-field basis #13

Closed ritz078 closed 4 years ago

ritz078 commented 5 years ago

The exact issue can be seen on https://github.com/ritz078/transform/issues/93

Add an option to do this

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct RootInterface {
    some_object_with: String,
    a_lot_of_fields: String,
    which_quickly_becomes: String,
    hard_to_read: String,
}

instead of this

#[derive(Serialize, Deserialize)]
struct RootInterface {
    #[serde(rename = "someObjectWith")]
    some_object_with: String,
    #[serde(rename = "aLotOfFields")]
    a_lot_of_fields: String,
    #[serde(rename = "whichQuicklyBecomes")]
    which_quickly_becomes: String,
    #[serde(rename = "hardToRead")]
    hard_to_read: String,
}
evestera commented 4 years ago

Implemented now in release 0.4. The option is also supported in the Kotlin codegen.

ritz078 commented 4 years ago

Thank you ❤️