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

Adjacently tagged enum does not respect skip_serializing_if #1968

Open
davidMcneil opened this issue Jan 25, 2021 · 1 comment
Open

Adjacently tagged enum does not respect skip_serializing_if #1968

davidMcneil opened this issue Jan 25, 2021 · 1 comment

Comments

@davidMcneil
Copy link

Here is an example showing the actual and expected output:

use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize)]
#[serde(tag = "key", content = "value")]
enum MyEnum {
    A(#[serde(skip_serializing_if = "Option::is_none")] Option<u32>),
}

#[test]
fn it_works() {
    let a = MyEnum::A(None);
    // The actual output
    assert_eq!(
        "{\"key\":\"A\",\"value\":null}",
        serde_json::to_string(&a).unwrap()
    );
    // The expected output
    assert_eq!("{\"key\":\"A\"}", serde_json::to_string(&a).unwrap());
}
@Mingun
Copy link
Contributor

Mingun commented May 21, 2023

Internally this is handled by the same code as the one in #2105, so technically one is duplicate of another

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants