birkenfeld/serde-pickle

Panic deserializing nested enum/struct/enum with mixed serde "tag"

jzrake opened this issue · 2 comments

This code panics when the outer enum uses serde's internal tagging and the inner enum uses external (default) tagging. If both enum's have internal tagging, then the test passes.

use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
#[serde(tag = "type")] // <- comment this to fail the test
enum InnerEnum {
    Opt
}

#[derive(Serialize, Deserialize)]
struct MiddleStruct {
    option: InnerEnum
}

#[derive(Serialize, Deserialize)]
#[serde(tag = "type")]
enum OuterEnum {
    Inner(MiddleStruct)
}

#[test]
fn nested_structs_with_mixed_tag_convention() {
    let inner  = InnerEnum::Opt;
    let middle = MiddleStruct{option: inner};
    let outer  = OuterEnum::Inner(middle);

    let data = serde_pickle::to_vec(&outer, true).unwrap();
    let _: OuterEnum = serde_pickle::from_slice(&data).unwrap(); // <- fails on deserialize
}

Thanks for the report, I missed it originally. I can't pinpoint the problem here, but it seems to go away when switching enum serialization to the commonly expected model - see #9 - which I'll switch to for the 1.0 release.

Ok, the new default is now implemented; if you are still interested it would be nice if you could test out master before I release 1.0.