I am querying an API for some data but their keys have hyphens instead of underscores in their names, and since I can't have hyphens in struct field names, I am unable to cast it.
For example, my struct:
pub struct Example {
user_id: String,
name: String,
}
and the received json is like
{
"user-id": "abc",
"name": "John"
}
Right now i'm doing this but i can't because i can't directly cast it
let res = client
.get("SOME-URL")
.header("x-api-key", APP_ID)
.send()
.await?;
let response_body: Example = res.json().await?;
#[serde(rename_all = "kebab-case")]
at the struct level, (2) use#[serde(rename = "user-id")]
at the field level. – Pelfrey