google / google/built_value.dart
Add support for Deserialization only
- Dominant language
- Dart
- Stars
- 886
- Forks
- 195
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 4
Description
I have some Value Objects that are representations from a Firebase Cloud Firestore database. Those VOs need to hold the document id they have on the database, so later I can update or delete them, using that `id`.
My VOs look like:
```dart
abstract class MyClass implements Built {
static Serializer get serializer => _$myClassSerializer;
@BuiltValueField(serialize: false)
String get id;
...
```
And I construct them with Firestore like:
```dart
return serializers.deserializeWith(
MyClass.serializer,
document.data()..putIfAbsent('id', () => document.id),
);
```
So upon deserialization I add the document's `id` into the serialized data so it can be easily passed to the VO.
The problem is `@BuiltValueField(serialize: false)` cancels serialization AND deserialization (silly me got things literal and thought it would only cancel the serialization itself, not the deserialization).
I know I can make it `@nullable` or add a default value, but this isn't a perfect solution as neither `null` or a default value are correct or acceptable for an `id` and can creep errors into the App.
Could we have a mechanism for selecting if we want `serialization`, `deserialization` or `both`? Maybe an extra enum field for configuring the `serialization`?
Contributor guide
Assessment
This issue has not been assessed yet.