serde-yaml icon indicating copy to clipboard operation
serde-yaml copied to clipboard

Allow Configuration on Option::None handling

Open bnheise opened this issue 2 years ago • 1 comments

Currently if you have an optional field in Rust:

struct Something {
  maybe_not_there: Option<String>
}

Something {
  maybe_not_there: None
}

And you serialize it using this crate, you get this:

something
  maybe_not_there: null

However, valid yaml accepts also a tilde, no value at all, or simply omitting the key altogether.

Valid:

something
  maybe_not_there: ~

something
  maybe_not_there:

something

It would be nice if it were possible to configure the desired output.

bnheise avatar Jan 30 '23 05:01 bnheise

For the last option, ref. https://docs.rs/serde_with/3.0.0/serde_with/attr.skip_serializing_none.html

nim65s avatar May 13 '23 21:05 nim65s