google / google/json_serializable.dart
Default value for record fields
- Dominant language
- Dart
- Stars
- 1.6k
- Forks
- 461
- Avg merge
- 45m
- Merged PRs (30d)
- 1
Description
Since Version 6.7.0 Records are supported.
If I am right, there is currently no possibility to set a default value for a field inside the record.
For example:
```dart
@JsonSerializable()
class MyClass {
final ({
double numberWithDefault,
String someOtherText,
}) myRecord;
@JsonKey(defaultValue: 0.0)
final double anotherNumberWithDefault;
MyClass({
required this.myRecord,
required this.anotherNumberWithDefault,
});
factory MyClass.fromJson(Map json) => _$MyClassFromJson(json);
Map toJson() => _$MyClassToJson(this);
}
```
It would be nice to be able to set `numberWithDefault` to a default value, if the json value is null (just like `anotherNumberWithDefault`).
Contributor guide
Assessment
This issue has not been assessed yet.