Warning
This post was published 56 days ago. The information described in this article may have changed.
I'm trying to deserialize JSON structures like below while making the best possible use of enums:
{
"id": "1",
"schema": "Person",
"properties": {
"name": "John Doe"
}
}
but also
{
"id": "4",
"schema": "Company",
"properties": {
"employee_count": 42,
}
}
Is it at all possible to have something like this to deserialize into? Or do I need a custom deserializer?
#[derive(Debug, Deserialize)]
#[serde(tag = "schema", content = "properties")]
enum EntityType {
Person {
name: String,
},
Company {
employee_count: usize,
},
}
2 posts - 2 participants
🏷️ rust_feed