google / google/json_serializable.dart

Inheritable JsonKey with Freezed

Open
#885 6 comments 6 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
1.6k
Forks
461
Avg merge
45m
Merged PRs (30d)
1

Description

This issue is related to https://github.com/rrousselGit/freezed/issues/423

**Is your feature request related to a problem? Please describe.**
I'm building an API wrapper, and I'm dealing with two JSON object that have numerous shared keys and only a few specific ones. I have an interface like this to implement this:

```dart
abstract class MyBaseType {
@JsonKey(name: 'property_key')
final String property;
}
```

And a couple of freezed classes like this:

```dart
@freezed
class MySpecializedType extends MyBaseType with _$MySpecializedType {
const MySpecializedType._();

const factory MySpecializedType({
required String property,
@JsonKey(name: 'another_propery_key') required String anotherProperty,
}) = _MySpecializedType
}
```

Normally, when using json_serializable, the JsonKey annotation in the base class will be used in subclasses. This is not happening when using freezed.

**Describe the solution you'd like**
I'd like JsonKey annotations used in superclasses to be used in freezed subclasses as well.

**Describe alternatives you've considered**
The only alternative is writing the same annotation everywhere it's needed.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.