I am deserializing some JSON using Serde. I am having problems with a value that is usually an array of strings, but can also be the constant string "all". Expressed in JSON-schema it looks like this:
{
"oneOf": [
{
"const": "all"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
I want to serialize it into this enum:
enum MyList {
List(Vec<String>),
All
}
Here are a few examples:
["foo", "bar"] // Should be MyList::List
"all" // Should be MyList::All
"foo" // Should be an error!
The question is, how do I deserialize this enum using serde? None of the container attributes or variant attributes seem to help. If need be, I may change the design of the enum. However, the structure of the JSON is beyond my control.