google / google/json_serializable.dart
[Question/Feature Request?] Support generics serialization from parent
- Dominant language
- Dart
- Stars
- 1.6k
- Forks
- 461
- Avg merge
- 45m
- Merged PRs (30d)
- 1
Description
I'm using jsonserializable, and having an issue with generics. I read on how to "solve" serialization for class A that has generic type T - but I'm thinking on why do I even need to specify some solution, if class A is inside Class B, and class B already knows about the type.
Perhaps there's a better way to model it ?
Example:
```
class MyData {
final T value;
final bool preferred;
}
@freezed
class Profile with $Profile {
const factory Profile({ MyData fruits, MyData cakes }) = _Profile;
// Fruit and Cake are strongly typed enums.
// .. fromJson
}
```
So while I understand why the system can't serialize MyData - it should be able to serialize fruits and cakes` variables; right?
Any way to do that then?
Contributor guide
Assessment
This issue has not been assessed yet.