We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JsonKey.fromJson
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.
JsonConverter
JsonKey.name
The text was updated successfully, but these errors were encountered:
Seems that putting the top level fromJson function in the same file resolve it. So now it works, but why? I'm not using lib prefixes.
fromJson
Demo video: https://mega.nz/file/FHZ1hAaA#rzsGJsyePyDpDr-okfCF9QRQ_GCIF1zSWvW2bPtPK90
Sorry, something went wrong.
No branches or pull requests
My code:
Generated:
Any solution?
UPDATE:
JsonConverter
is not a solution because in many cases I need to specify theJsonKey.name
too.The text was updated successfully, but these errors were encountered: