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]: Nested options fail to deserialize at run-time #127

Open
2 tasks done
hniksic opened this issue Jun 10, 2024 · 0 comments
Open
2 tasks done

[Bug]: Nested options fail to deserialize at run-time #127

hniksic opened this issue Jun 10, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@hniksic
Copy link

hniksic commented Jun 10, 2024

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 code fails to deserialize Some(None):

use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct Foo(Option<Option<bool>>);

fn main() {
    for o in [None, Some(None), Some(Some(true)), Some(Some(false))] {
        let o = Foo(o);
        let mut ser = vec![];
        ciborium::into_writer(&o, &mut ser).unwrap();
        let o2: Foo = ciborium::from_reader(&mut ser.as_slice()).unwrap();
        if o != o2 {
            println!("error: {o:?} deserialized as {o2:?}");
        }
    }
}

Running the above code prints:

error: Foo(Some(None)) deserialized as Foo(None)

Expected Behaviour

I expected Some(None) to round-trip through ciborium as Some(None) (i.e. the above program to output nothing). We are investigating ciborium for types that use deserialize_any(), and inability to deserialize nested options is an issue.

I control the code that does the (de-)serialization, so if it's a matter of setting up some configuration, that'd work for me.

Environment Information

$ uname -a
Linux snijeg 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
$ enarx --version
zsh: command not found: enarx

Steps To Reproduce

Run the included code, and observe the result.

@hniksic hniksic added the bug Something isn't working label Jun 10, 2024
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