ciborium
ciborium copied to clipboard
[Bug]: `#[serde(other)]` broken when deserializing from `Value`
Is there an existing issue for this?
- [X] I have searched the existing issues
Code of Conduct
- [X] 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