google / google/built_value.dart
Is it possible to distinguish between absent (no value) and null when serializing?
- Dominant language
- Dart
- Stars
- 886
- Forks
- 195
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 4
Description
Let's say I have a SimpleValue class with a nullableString:
```dart
abstract class SimpleValue implements Built {
@BuiltValueSerializer(serializeNulls: true)
static Serializer get serializer => _$simpleValueSerializer;
String? get nullableString;
factory SimpleValue([void Function(SimpleValueBuilder) updates]) = _$SimpleValue;
SimpleValue._();
}
```
I would like to be able to have this behaviour when serializing to JSON:
```dart
final noValue = SimpleValue();
print(serializers.toJson(SimpleValue.serializer, value)); // should print {}
final nullValue = SimpleValue((value) => value.nullableString = null);
print(serializers.toJson(SimpleValue.serializer, nullValue)); // should print { "nullableString": null }
```
Is it possible?
Contributor guide
Assessment
This issue has not been assessed yet.