Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate serde; // 1.0.78
- #[macro_use] extern crate serde_derive; // 1.0.78
- extern crate serde_json; // 1.0.27
- #[derive(Deserialize, Debug)]
- struct Foo {
- #[serde(flatten)]
- bar: StringIsh,
- }
- #[derive(Deserialize, Debug)]
- #[serde(untagged)]
- enum StringIsh {
- String(String),
- Int(u64),
- }
- fn main() {
- println!(
- "{:#?}",
- serde_json::from_str::<Vec<Foo>>(r#"[{"bar": "42"}, {"bar": 42}]"#)
- );
- }
Add Comment
Please, Sign In to add comment