google / google/json_serializable.dart
`JsonKey.fromJson` seems to be ignored
- Dominant language
- Dart
- Stars
- 1.6k
- Forks
- 461
- Avg merge
- 45m
- Merged PRs (30d)
- 1
Description
My code:
```dart
@JsonSerializable()
class Person {
@JsonKey(
fromJson: unixTimeToDateTime,
toJson: dateTimeToUnixTime,
includeFromJson: true,
includeToJson: true,
)
DateTime dateOfBirth;
Person({required this.dateOfBirth});
}
DateTime unixTimeToDateTime(int secondsSinceEpoch) =>
DateTime.fromMillisecondsSinceEpoch(
secondsSinceEpoch * 1000,
isUtc: true,
);
int dateTimeToUnixTime(DateTime dateTime) =>
dateTime.millisecondsSinceEpoch ~/ 1000;
```
Generated:
```dart
Person _$PersonFromJson(Map json) => Person(
dateOfBirth: DateTime.parse(json['dateOfBirth'] as String),
);
```
Any solution?
UPDATE:
`JsonConverter` is not a solution because in many cases I need to specify the `JsonKey.name` too.
Contributor guide
Assessment
This issue has not been assessed yet.