trevorwang / retrofit.dart

retrofit.dart is an dio client generator using source_gen and inspired by Chopper and Retrofit.
https://mings.in/retrofit.dart/
MIT License
1.06k stars 241 forks source link

Response type of list of models with generic field -> Generates code with error #681

Open moshe5745 opened 1 month ago

moshe5745 commented 1 month ago

To Reproduce

import 'package:json_annotation/json_annotation.dart';

part 'api_response.g.dart';

@JsonSerializable(genericArgumentFactories: true)
class SomeModelWithGenericType<T> {
  final T data;

  SomeModelWithGenericType(
      {required this.data,
    });

  factory SomeModelWithGenericType.fromJson(Map<String, dynamic> json, T Function(Object? json) fromJsonT) => _$SomeModelWithGenericTypeFromJson(json, fromJsonT);

  Map<String, dynamic> toJson(Object? Function(T) toJsonT) => _$SomeModelWithGenericTypeToJson(this, toJsonT);
}

class SomeModel {
   final String name;
}

  @GET('/some/api')
  Future<List<SomeModelWithGenericType<SomeModel>>> getSomething();

Expected behavior To generate code without errors

Screenshots image

Flutter 3.22.0 • channel stable

dependencies:
  json_annotation: ^4.9.0

dev_dependencies:
  json_serializable: ^6.8.0
  retrofit_generator: ^8.1.0
  build_runner: '>=2.4.10 <4.0.0'