Skip to content

Does this seem to be a bug from deserializing enum? #2948

@MillerVictor

Description

@MillerVictor

serde version info

└── serde_derive v1.0.219 (proc-macro)
    ├── proc-macro2 v1.0.95
    │   └── unicode-ident v1.0.18
    ├── quote v1.0.40
    │   └── proc-macro2 v1.0.95 (*)
    └── syn v2.0.104
        ├── proc-macro2 v1.0.95 (*)
        ├── quote v1.0.40 (*)
        └── unicode-ident v1.0.18

serde v1.0.219
└── serde_derive v1.0.219 (proc-macro) (*)

serde_json v1.0.141
├── itoa v1.0.15
├── memchr v2.7.5
├── ryu v1.0.20
└── serde v1.0.219
    └── serde_derive v1.0.219 (proc-macro)

system info

stable-x86_64-pc-windows-msvc (active, default)
rustc 1.88.0 (6b00bc388 2025-06-23)

same rust code example

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Vote {
    vote_address: String,
    vote_count:u64,
}

pub type Votes = Vec<Vote>;


#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum Case {
    VoteWitnessContract {
        owner_address: String,
      
        votes: Votes,
    },
    FreezeBalanceV2Contract{
        frozen_balance:i128,
        owner_address:String,
    }
}


#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Content{
    data:Vec<Case>
}

#[test]
fn test_case(){
    let response =  r#"{"data":[{"owner_address":"41cf418b1cd1a610e8b370abc1e428848f82e3a153","votes":[{"vote_address":"4136b8367bdad6b910a86e1d8af121c870d9e12a71","vote_count":900}]},{"frozen_balance":500000000,"owner_address":"41cf418b1cd1a610e8b370abc1e428848f82e3a153"}]}"#;
    serde_json::from_str::<Content>(&response).unwrap();

}

Error info

---- case::test_case stdout ----
thread 'case::test_case' panicked at src\case.rs:33:48:
called `Result::unwrap()` on an `Err` value: Error("data did not match any variant of untagged enum Case", line: 1, column: 251)

Enum Excerpted from official examples #[serde(untagged)]

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