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

Problem deserializing tagged enum (serde) #548

Closed
jbrosi opened this issue Jun 3, 2022 · 5 comments · Fixed by #584
Closed

Problem deserializing tagged enum (serde) #548

jbrosi opened this issue Jun 3, 2022 · 5 comments · Fixed by #584

Comments

@jbrosi
Copy link

jbrosi commented Jun 3, 2022

Hey there, I have the following code:

use serde::{Deserialize, Serialize};

fn main() {
     #[derive(Debug, Serialize, Deserialize)]
    struct Struct {
        a: u8,
    }
    #[derive(Debug, Serialize, Deserialize)]
    #[serde(tag = "version")]
    enum Test {
        Variant(Struct),
    }

    let data = Test::Variant(Struct { a: 7 });
    let serialized = bincode2::serialize(&data).unwrap();
    let deserialized: Test = bincode2::deserialize(&serialized).unwrap();

}

The deserialize fails with DeserializeAnyNotSupportedwhen I have the #[serde(tag="version")] enabled like above. If i remove it, it does work. Serialize always works and seems to put additional info when tagging is enabled. Couldn't find any hints on how to solve this and this does not seem to be known issue (https://docs.rs/bincode/2.0.0-alpha.1/bincode/serde/index.html#known-issues).

The behavior is the same for bincode 2.0.1 and 1.3.3.

@jbrosi jbrosi changed the title Problem deserializing tagged enum Problem deserializing tagged enum (serde) Jun 3, 2022
@VictorKoenders
Copy link
Contributor

Looks like we have a new entry for the known issue list with serde, where this will just not work with bincode.

@huntc
Copy link

huntc commented Jun 9, 2022

Any explanation on why tags cannot work with bincode? Thanks.

@ZoeyR
Copy link
Collaborator

ZoeyR commented Jun 9, 2022

Its because the serde codegen when using tags calls unsupported methods in bincode. Specifically the deserialize_any function. Bincode is not a self-describing format and it can't figure out the shape of data from the data itself.

@yottacto
Copy link

yottacto commented Sep 5, 2022

any solutions to this?

@VictorKoenders
Copy link
Contributor

No, this is a fundamental incompatibility between serde and data formats that do not have metadata

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants