Skip to content
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

RawValue does not work inside an internally tagged enum #779

Open
rklaehn opened this issue May 21, 2021 · 0 comments
Open

RawValue does not work inside an internally tagged enum #779

rklaehn opened this issue May 21, 2021 · 0 comments

Comments

@rklaehn
Copy link

rklaehn commented May 21, 2021

This is similar, but not quite the same as #497. In this case it is a normally tagged enum.

Rust playground example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=4d9015b013535f143aa5b8ad829be43c

Code:

use serde_json::value::RawValue;
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
pub struct RequestBody {
    pub payload: Box<RawValue>,
}

#[derive(Serialize, Deserialize)]
#[serde(tag = "type")]
enum Incoming {
    Request {
        payload: Box<RawValue>,
    },
}

fn main() {
    let foo = Incoming::Request {
        payload: serde_json::value::to_raw_value(&42).unwrap()
    };
    let txt = serde_json::to_string(&foo).unwrap();
    let roundtrip: Incoming = serde_json::from_str(&txt).unwrap();
}
@dtolnay dtolnay changed the title RawValue does not work in an enum RawValue does not work in an internally tagged enum Jan 22, 2022
@dtolnay dtolnay changed the title RawValue does not work in an internally tagged enum RawValue does not work inside an internally tagged enum Jan 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant