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.09k stars 250 forks source link

int.fromJson() generated #573

Open Dekhant opened 1 year ago

Dekhant commented 1 year ago

Describe the bug generating fromJson to basic types.

I have this request

  @GET('/groups')
  Future<Map<String, List<int>>> getGroups(
    @Header('Authorization') String accessToken,
  );

and this is output that generated by retrofit:

@override
  Future<Map<String, List<int>>> getGroups(String accessToken) async {
    const _extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final _headers = <String, dynamic>{r'Authorization': accessToken};
    _headers.removeWhere((k, v) => v == null);
    final Map<String, dynamic>? _data = null;
    final _result = await _dio.fetch<Map<String, dynamic>>(
        _setStreamType<Map<String, List<int>>>(Options(
      method: 'GET',
      headers: _headers,
      extra: _extra,
    )
            .compose(
              _dio.options,
              '/groups',
              queryParameters: queryParameters,
              data: _data,
            )
            .copyWith(baseUrl: baseUrl ?? _dio.options.baseUrl)));
    var value = _result.data!.map((k, dynamic v) => MapEntry(
        k,
        (v as List)
            .map((i) => int.fromJson(i as Map<String, dynamic>))
            .toList()));
    return value;
  }

and error appears in this line:

int.fromJson(i as Map<String, dynamic>))
932707629 commented 1 year ago

Same thing with Map: (json) => Map<dynamic, dynamic>.fromJson(json as Map<String, dynamic>)