retrofit.dart
retrofit.dart copied to clipboard
Response type of list of models with generic field -> Generates code with error
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
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'