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

[Bug]: #[serde(other)] broken when deserializing from Value #55

Open
2 tasks done
acfoltzer opened this issue Aug 30, 2022 · 0 comments
Open
2 tasks done

[Bug]: #[serde(other)] broken when deserializing from Value #55

acfoltzer opened this issue Aug 30, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@acfoltzer
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Current Behaviour

The following test fails with

'called `Result::unwrap()` on an `Err` value: Custom("invalid type: integer `42`, expected unit")'
#[test]
fn serde_other_value() {
    #[derive(Deserialize)]
    enum E {
        A(u32),
        #[serde(other)]
        Unknown,
    }

    #[derive(Serialize)]
    enum F {
        A(u32),
        B(u64),
        #[serde(other)]
        Unknown,
    }

    let mut buf = vec![];
    let b = F::B(42);
    ciborium::ser::into_writer(&b, Cursor::new(&mut buf)).unwrap();
    let unk_from_reader: E = ciborium::de::from_reader(Cursor::new(&buf)).unwrap();
    // It works when deserializing directly from the reader
    assert!(matches!(unk_from_reader, E::Unknown));

    let v: ciborium::Value = ciborium::de::from_reader(Cursor::new(&buf)).unwrap();
    let unk_from_value: E = v.deserialized().unwrap();
    // This is the failing assertion
    assert!(matches!(unk_from_value, E::Unknown));
}

Expected Behaviour

I expect the Unknown variant to be deserialized regardless of whether there's an intermediate Value step.

Environment Information

N/A

Steps To Reproduce

No response

@acfoltzer acfoltzer added the bug Something isn't working label Aug 30, 2022
@dpal dpal added this to Enarx Board Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: New
Development

No branches or pull requests

1 participant