Expanding on my previous question, how do you handle an array that contains mixed structs
that are both valid? I've tried looking at the serde_json::Value
source. However it doesn't handle the case of two different structs
.
I can't simply merge them, and use Options over their properties as that would make the single struct
unwieldy, and it is important for them to be distinct.
Rust structs
#[derive(Clone, Debug, Deserialize)]
struct WebResponse {
foo: Vec<Structs>,
}
enum Structs {
Foo(Foo),
Bar(Bar),
}
#[derive(Clone, Debug, Deserialize)]
struct Foo {
name: String,
baz: Vec<String>,
}
#[derive(Clone, Debug, Deserialize)]
struct Bar {
quux: u64
}
Example JSON
{
"foo": [
{
"name": "John",
"baz": ["Lorem", "Ipsum"]
},
{
"quux": 17
}
]
}