-
Consider two possible JSON responses from an API: {
"some_key": ""
} {
"some_key": "12.33"
} Is there a way to apply both #[serde_as]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Response {
#[serde_as(as = "NoneAsEmptyString")]
#[serde_as(as = "DisplayFromStr")]
pub some_key: Option<f64>,
} |
Beta Was this translation helpful? Give feedback.
Answered by
jonasbb
Jul 11, 2024
Replies: 1 comment
-
Unfortunately it is impossible to combine multiple transformations. You can create you own type that implements the behavior of both combined. The documentation has some information how to get started and you can look at the implementation of both types. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jmcph4
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately it is impossible to combine multiple transformations. You can create you own type that implements the behavior of both combined. The documentation has some information how to get started and you can look at the implementation of both types.
https://docs.rs/serde_with/3.8.3/serde_with/guide/serde_as/index.html#implementing-serializeas--deserializeas