jsonserializable fails when using @JsonKey's fromJson and toJson directly with the generated methods, `$toOnePostFromJsonand_$toOnePostToJson`
Stack Trace
[SEVERE] json_serializable on lib/data/models/comment.dart:
Could not generate `toJson` code for `post`.
To support the type `ToOne` you can:
* Use `JsonConverter`
https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html
* Use `JsonKey` fields `fromJson` and `toJson`
https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html
https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html
package:post_reader_demo/data/models/comment.freezed.dart:181:21
╷
181 │ final ToOne<Post> post;
│ ^^^^
╵
package:json_serializable/src/encoder_helper.dart 188:7 EncodeHelper._serializeField
package:json_serializable/src/encoder_helper.dart 112:42 EncodeHelper._writeToJsonSimple.<fn>
dart:core StringBuffer.writeAll
package:json_serializable/src/encoder_helper.dart 109:9 EncodeHelper._writeToJsonSimple
package:json_serializable/src/encoder_helper.dart 85:7 EncodeHelper.createToJson
dart:_internal WhereIterator.moveNext
package:json_serializable/src/json_part_builder.dart 64:27 _UnifiedGenerator.generate
package:source_gen/src/builder.dart 355:23 _generate
The same works when there is a non generated method, _toOnePostFromJson and _toOnePostToJson , which proxies the request to the generated method.
Given the following class
jsonserializable fails when using
@JsonKey
'sfromJson
andtoJson
directly with the generated methods, `$toOnePostFromJsonand
_$toOnePostToJson`Stack Trace
The same works when there is a non generated method,
_toOnePostFromJson
and_toOnePostToJson
, which proxies the request to the generated method.Reproducible project at https://github.com/ibrahim-mubarak/post_reader_demo
Relevant file https://github.com/ibrahim-mubarak/post_reader_demo/blob/main/post_reader_demo/lib/data/models/post.dart
Output of
flutter --version