Skip to content

RawValue does not work inside an internally tagged enum #779

Open
@rklaehn

Description

@rklaehn

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();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions