Support serde rename_all
#[serde(rename_all = "snake_case")]
pub enum CanisterStatusType {
Running,
Stopping,
Stopped,
}
Discussed https://github.com/dfinity-lab/dfinity/pull/4812
We experienced this problem today. This issue makes it impossible to have a struct that derives both CandidType and serde Serialize. For example:
#[derive(CandidType, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct Person {
first_name: String,
last_name: String,
}
In this case:
serde_json::from_value(serde_json::json!(person))-> OKcandid::Decode!(candid::Encode!(person), Person)-> Error
Is there any plan to fix it?
As a workaround, you can use #[serde(rename = "")] instead.
struct Person {
#[serde(rename = "firstName")]
first_name: String,
#[serde(rename = "lastName")]
last_name: String,
}
@chenyan-dfinity Yes, that's a valid workaround even if some of my structs have more than 30 fields :disappointed_relieved:
Anyway, while this is not supported, you should break the compilation or at least inform the user with a warning, in fact, this compiles but fails at runtime when a canister calls an endpoint that uses this type:
#[derive(CandidType, Deserialize)]
#[serde(rename_all = "camelCase")]
struct Person {
first_name: String,
last_name: String,
}
+1 to initial request to support #[serde(rename_all = "snake_case")].