-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjacently tagged enum not deserialisable; ExpectedMap #87
Comments
Does the same approach work when you use the equivalent in serde_json? |
I will properly test and confirm tomorrow when I'm at my desk again, but just quickly checking on my phone I see that it handles deserialize_struct in a way that also handles arrays: https://github.com/serde-rs/json/blob/4bc1eaa03a6160593575bc9bc60c94dba4cab1e3/src/de.rs#L1808 |
Can confirm that this works: let user = r#"
{
"id": "clnofe2cg0000ayeq6ryddrzw",
"background": ["Video", {"duration": 7960, "url": "https://google.nl"}]
}"#;
// Parse the string of data into serde_json::Value.
let user: Result<User, serde_json::Error> = serde_json::from_str(user);
match user {
Ok(user) => println!("user: {:#?}", user),
Err(e) => println!("error: {:#?}", e),
}
|
serde and serde_json have support for deserializing structs and adjacently-tagged enums from sequences. I had no idea! #[derive(serde::Deserialize)] struct Person { name: String, age: u8, } let input = r#"["Arthur Dent", 42]"#; let person: Person = serde_json::from_str(input).unwrap(); assert_eq!(person.name, "Arthur Dent"); assert_eq!(person.age, 42); Fixes #87
I didn't even realize this was a thing! |
Thanks for reporting this! Fixed in 4.2.10. |
Ah thanks so much for the fast fix! Awesome 🎉 |
I'm trying to deserialize my database which has a Map with a List as an enum, like background: ["Video", {url: "", duration:0}]
This should be supported by serde, but I'm now having a feeling it's not supported by serde_dynamo for some reason?
I found this issue where it's possible: serde-rs/serde#2479
deserialize_struct always calls deserialize_map and errors if it doesn't see a map as the value:
serde_dynamo/src/de/deserializer.rs
Line 292 in 2940408
Let me know if I'm doing something wrong :)
The text was updated successfully, but these errors were encountered: