Support internally tagged enums
jfizz opened this issue · comments
jfizz commented
As described in the serde docs: https://serde.rs/enum-representations.html#internally-tagged.
The current behavior
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ProductItem {
pub details: ProductItemDetails,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
pub enum ProductItemDetails {
Card(CardDetails),
Gift(GiftDetails),
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct GiftDetails {
pub for_item: usize,
}
...
which results in
unknown variant `type`, expected one of `card`, `gift`
For reference, the DynamoDB item would look like (in JSON format):
{
"details": {
"type": "gift",
"for_item": 0
}
}