retrofit.dart
retrofit.dart copied to clipboard
issue `@JsonSerializable(genericArgumentFactories: true)` combine with `Use Flutter compute for parsing models`
hi @FaKenKoala ,
I have faced with a problem when trying to use @JsonSerializable(genericArgumentFactories: true)
combine with Use Flutter compute for parsing models, it's generated an error code and I try to manual modified generated code to :
1, in JSON model
BaseResponse<T> deserializeBaseResponse<T>(List params) =>
BaseResponse.fromJson(params.firstOrNull, params.lastOrNull);
Map<String, dynamic> serializeBaseResponse<T>(List params) =>
params.firstOrNull?.toJson(params.lastOrNull);
@JsonSerializable(
genericArgumentFactories: true,
)
class BaseResponse<T> {
final T? data;
final List<Message>? messages;
BaseResponse(this.data, this.messages);
2, in retrofit generated code for service when using @RestApi(parser: Parser.FlutterCompute,)
final BaseResponse<List<ApplicationResponse>> value =
await compute(deserializeBaseResponse, [
_result.data!,
(json) => (json as List<dynamic>)
.map<ApplicationResponse>(
(i) => ApplicationResponse.fromJson(i as Map<String, dynamic>))
.toList()
]);
final httpResponse = HttpResponse(value, _result);
return httpResponse;
and it's working fine, but for the long term, could u add more code logic to support this issue.
Thanks for your effort!
Originally posted by @vannt1991 in https://github.com/trevorwang/retrofit.dart/issues/399#issuecomment-1070439099
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@FaKenKoala could u take a look at it, many thanks!
It's great if this feature can be provided. multi-argument is needed for generic classes