google / google/json_serializable.dart
[Feature Request] `includeIfDefault`
- Dominant language
- Dart
- Stars
- 1.6k
- Forks
- 461
- Avg merge
- 45m
- Merged PRs (30d)
- 1
Description
Would be extremely helpful to have a similar configuration flag like `includeIfNull` but for the `defaultValue`. By default would be set to `true`.
This would be great to use when working with firestore but you don't want to deal with nulls in app but rather use defaults.
So this would basically enable the developer to declare a default value for a field but also skip writing to firestore when the value is the default, since there's really no gains in storing the default in firestore other than increasing your storage size.
Usage:
```
@JsonKey(defaultValue: '', includeIfDefault: false)
final String value;
```
```
@JsonKey(defaultValue: [], includeIfDefault: false)
final List values;
```
Contributor guide
Assessment
This issue has not been assessed yet.