Skip to content

Inheritable JsonKey with Freezed #885

@torbenkeller

Description

@torbenkeller

This issue is related to rrousselGit/freezed#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:

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

And a couple of freezed classes like this:

@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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions