Problems with round tripping untagged unions.
Closed this issue · 3 comments
I was trying to debug a mysterious issue while investigating a bug. My implementations of serialize and deserialize were complicated but look like they should match. After extensive investigation I discovered that if I used serde_json
they did match, but when I used ron
they did not. I was able to reduce the input to this playground which uses serde_json
and passes. Unfortunately ron
is not available on playground, but this test fails running locally:
#[test]
fn serde_test() {
#[derive(serde::Deserialize, serde::Serialize, PartialEq, Eq, Debug)]
#[serde(untagged)]
enum EitherInterval<V> {
B(Interval<V>),
D(V, Option<V>),
}
type Interval<V> = (Bound<V>, Bound<V>);
let t = EitherInterval::B((Excluded(0u8), Unbounded));
let s = ron::ser::to_string(&t).unwrap();
let r = ron::de::from_str(&s).unwrap();
assert_eq!(t, r);
}
Is this a bug? Is there a known workaround?
Thanks for reaching out, @Eh2406. On the last version, it seems that this is now working. Could you try your code with version ron = "=0.9.0-alpha.0"
(the prerelease for v0.9) and see if it works? If v0.9 does indeed fix the issue, I'll merge your testcase into our testsuite in #531 to ensure it continues working in the future :)
Thank you for the fast response. I will give it a try as soon as I have a chance. I have a larger test case set up on my work computer, so may not get to it until Monday.