-
-
Notifications
You must be signed in to change notification settings - Fork 791
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
Combine "transparent" and "skip_serializing_if" tags #1870
Comments
What would you want the serialized representation to be if skipped? |
By which I mean, in the case of something like: use serde::Serialize;
#[derive(Serialize)]
#[serde(transparent)]
struct Foo {
#[serde(skip_serializing_if = "String::is_empty")]
inner: String,
}
fn main() {
let empty_foo = Foo { inner: String::new() };
println!("{}", serde_json::to_string(&empty_foo).unwrap());
} |
Well, is there something like an empty serialization? |
To clarify the intent, I would like to use this on an optional field, not on the top-level serialization object. |
Related: #65 (comment) |
There isn't something like an empty serialization. When a Serialize impl runs, the only way it can succeed is by serializing something. The thing whose field this is can decide not to serialize that field, though. |
I would like to have a transparent struct with a single field, whose serialization is skipped if some condition is fulfilled:
However, if the
transparent
tag is included, the inner tag is ignored, i.e. this compiles:Is this expected behaviour?
The text was updated successfully, but these errors were encountered: