[Feature Request] Add `skip_serializing_if_default` to skip fields equal to their default value
Author: qiu-nonameCreated Aug 13, 2026Updated Aug 13, 2026
The following content was written by a human and translated using AI.
I noticed that skip_serializing_if is often used with predicates such as:
#[serde(skip_serializing_if = "Option::is_none")]
value: Option<T>,
#[serde(skip_serializing_if = "Vec::is_empty")]
value: Vec<T>,
#[serde(skip_serializing_if = "is_zero")]
value: usize,Would it be possible to add something like skip_serializing_if_default?
For example:
#[serde(skip_serializing_if_default)]
value: T,The idea would be to skip serialization when the value is equal to T::default().
This could cover many common cases such as Option::is_none, Vec::is_empty, zero values, empty strings, false, etc., and would avoid defining a custom predicate for each type.
Source: serde-rs/serde