Skip to content

Better support for deserializing enum variants #11

Closed
@spyoungtech

Description

@spyoungtech

right now, this fails:

        use serde::Deserialize;
        use crate::from_str;
        #[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
        #[serde(rename_all="snake_case")]
        enum SomeEnum{
            VariantA(String),
            VariantB,
        }

        #[derive(Debug, Clone, Deserialize, Serialize)]
        struct SomeStruct {
            some_enum: SomeEnum
        }


        let json5 = r#"{some_enum: "variant_b" }"#;
        let parsed: SomeStruct = from_str(json5).unwrap();
        assert_eq!(parsed.some_enum, SomeEnum::VariantB);

This should work as it does in serde_json

Right now, we only consider Identifiers and JSONObjects (and only identifiers within JSONObjects) this should at least also consider strings, too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions