Open
Description
My code:
@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:
Person _$PersonFromJson(Map<String, dynamic> 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.
Metadata
Metadata
Assignees
Labels
No labels