Skip to content

#[serde_as(as = "Option<OneOrMany<_>>")]#[skip_serializing_none] fails to deserialize with None #311

@apps4uco

Description

@apps4uco

I have this code which fails. I believe it should be supported.

#[serde_as]
#[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct Demo {
    #[serde_as(as = "Option<OneOrMany<_>>")]
    contents: Option<Vec<String>>,
}

It serializes fine with a single element in a vector or multiple elements in a vector

It fails with an error when the contents are set to None

failures:

---- tests::vec_none stdout ----
None
Serialized ---
{}

Error: Message("missing field contents", Some(Pos { marker: Marker { index: 4, line: 2, col: 0 }, path: "." }))

Please find a test case attached.

Workaround: Dont specify #[skip_serializing_none]

test.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions