Is it possible to extend serde with custom attributes?
I want to deserialize json into a struct like struct Root { id: u32 }
, so id will always be u32.
But sometimes I get { "id": "42" }
instead of { "id": 42 }
. For now I've solved this problem with serde's deserialize_with and a custom function. But since I want to learn more about macros I would like to write
#[derive(Debug, Deserialize)]
struct Root {
#[serde(always(u32))]
id: u32
}
Is that possible?