-
Notifications
You must be signed in to change notification settings - Fork 606
Open
Description
This code
use serde::Deserialize;
use serde_json; // 1.0.39
use serde_json::value::RawValue;
#[derive(Deserialize, Debug)]
struct Struct<'a> {
#[serde(borrow)]
value: &'a RawValue,
}
#[derive(Deserialize, Debug)]
#[serde(tag = "a")]
enum Wrapper<'a> {
#[serde(rename = "s")]
S {
#[serde(borrow)]
data: Struct<'a>,
},
}
fn main() {
let message = r#"{
"a": "s",
"data": {
"value": 123
}
}"#;
let s: Wrapper = serde_json::from_str(message).unwrap();
println!("{:?}", s);
}
compiles and runs, but serde_json returns an error: invalid type: newtype struct, expected any valid JSON value
Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=84bc58188c5625ce5bbabd6a44da205a
drewhk, fzgregor, ababo, Avarel, d4h0 and 6 more
Metadata
Metadata
Assignees
Labels
No labels