google / google/built_value.dart
Cannot add non-instantiable BuiltValues to SerializersFor
- Dominant language
- Dart
- Stars
- 886
- Forks
- 195
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 4
Description
I have a non-instantiable interface that I made a custom discriminating serializer for, but it doesn't get added to the serializers when listed in `SerializersFor` unless I make it extend a `Built*` stub class to trick `isBuiltValue`:
https://github.com/google/built_value.dart/blob/5d912473ea5bd39a10834e40a498702f8c143738/built_value_generator/lib/src/serializer_source_class.dart#L127-L134
```dart
@BuiltValue(instantiable: false)
abstract class HeroForEpisodeResultHero implements BuiltFaker {
HeroForEpisodeResultHero rebuild(
void Function(HeroForEpisodeResultHeroBuilder) updates);
HeroForEpisodeResultHeroBuilder toBuilder();
/// The name of the character
@nullable
String get name;
@BuiltValueSerializer(custom: true)
static Serializer get serializer =>
_bg.InterfaceSerializer(
wireName: 'Character',
typeMap: {
'Droid': HeroForEpisodeResultHeroOnDroid,
'Human': HeroForEpisodeResultHeroOnHuman
},
);
}
abstract class BuiltFaker {}
```
Given that the workaround is fairly straightforward, I just wanted to make note this use case for when the check is refactored so that `@BuiltValue(instantiable: false) + serializer` is still doable afterwards
Contributor guide
Assessment
This issue has not been assessed yet.