Hi!
I need to de/serialize JSON messages such as the following:
{ ..., "command": "cmd1", "arguments": { <command-dependent> } }
So far so good, this fits the adjacently tagged enum representation.
The wrinkle is that for some commands the arguments field may be optional. I tried modelling this as
#[serde(tag = "command", content = "arguments")]
enum Command {
cmd1(Option<Cmd1Arguments>)
...
}
but Serde is not liking it and complains about "missing field `arguments`".
Any suggestions? (besides custom serialization)
Hi!
I need to de/serialize JSON messages such as the following:
So far so good, this fits the adjacently tagged enum representation.
The wrinkle is that for some commands the
argumentsfield may be optional. I tried modelling this asbut Serde is not liking it and complains about "missing field `arguments`".
Any suggestions? (besides custom serialization)