json_serializable.dart
json_serializable.dart copied to clipboard
JsonKey annotation in superclass is not being used for overriden getters
Consider a structure like the following:
abstract class MyBaseClass {
@JsonKey(name: 'myCustomGetterName');
String get myGetter;
@JsonKey(name: 'myCustomFieldName');
final String myField;
}
@JsonSerializable(createFactory: false)
class MySuperclass implements MyBaseClass {
@override
String get myGetter => 'myGetterValue';
@override
final String myField = 'myFieldValue';
Map<String, dynamic> toJson() => _$MySuperclassToJson(this);
}
I'd expect to see a JSON result like this:
{
"myCustomGetterName": "myGetterValue",
"myCustomFieldName": "myFieldValue"
}
Instead, the getter name isn't inherited, and I get this:
{
"myGetter": "myGetterValue",
"myCustomFieldName": "myFieldValue"
}
@kevmoo any updates on this?
Sadly, @emme1444 – there's no good way to fix this without potentially breaking folks due to a change in behavior.
We'll have to wait until the next breaking release.
This is maybe related with #1102