google / google/json_serializable.dart

JsonKey annotation in superclass is not being used for overriden getters

Open
#887 3 comments 5 reactions 1 assignee Claimed by @kevmoo View on GitHub
Next breaking change release Type: enhancement
Dominant language
Dart
Stars
1.6k
Forks
461
Avg merge
45m
Merged PRs (30d)
1

Description

Consider a structure like the following:

```dart
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 toJson() => _$MySuperclassToJson(this);
}
```

I'd expect to see a JSON result like this:

```json
{
"myCustomGetterName": "myGetterValue",
"myCustomFieldName": "myFieldValue"
}
```

Instead, the getter name isn't inherited, and I get this:

```json
{
"myGetter": "myGetterValue",
"myCustomFieldName": "myFieldValue"
}
```

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.