google / json_serializable.dart

Generates utilities to aid in serializing to/from JSON.
https://pub.dev/packages/json_serializable
BSD 3-Clause "New" or "Revised" License
1.56k stars 400 forks source link

UnimplementedError: (TypeParameterTypeImpl) T #1047

Closed leshkovichpvl closed 2 years ago

leshkovichpvl commented 2 years ago

Flutter 2.5.3 • channel stable, json_serializable: 6.0.1

import 'package:json_annotation/json_annotation.dart';

part 'pageable_list.g.dart';

@JsonSerializable(explicitToJson: true, genericArgumentFactories: true)
class PageableList<T> {
  const PageableList({required this.edges});

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

  final List<Edge<T>> edges;

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

}

@JsonSerializable(genericArgumentFactories: true)
class Edge<T> {
  Edge({
    required this.node,
    required this.cursor,
  });

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

  final String cursor;
  final T node;

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

Error:

[INFO] Running build...
[INFO] 1.1s elapsed, 0/10 actions completed.
[INFO] 2.1s elapsed, 0/10 actions completed.
[INFO] 3.1s elapsed, 0/10 actions completed.
[SEVERE] json_serializable:json_serializable on lib/src/utils/pagination/pageable_list.dart:

UnimplementedError: (TypeParameterTypeImpl) T
[INFO] 10.0s elapsed, 1/10 actions completed.

I'm guessing the problem might be with List<Edge<T>> ?

kevmoo commented 2 years ago

Please run with --verbose!

kevmoo commented 2 years ago

...and include the information

leshkovichpvl commented 2 years ago

Please run with --verbose!

UnimplementedError: (TypeParameterTypeImpl) T
package:json_serializable/src/utils.dart 194:3                         typeToCode
dart:_internal                                                         ListIterable.join
package:json_serializable/src/utils.dart 190:48                        typeToCode
package:json_serializable/src/type_helpers/json_helper.dart 133:17     JsonHelper.deserialize
package:json_serializable/src/type_helper_ctx.dart 68:29               TypeHelperCtx.deserialize.<fn>
dart:core                                                              Iterable.firstWhere
package:json_serializable/src/type_helper_ctx.dart 88:46               TypeHelperCtx._run
package:json_serializable/src/type_helper_ctx.dart 65:19               TypeHelperCtx.deserialize
package:json_serializable/src/type_helpers/iterable_helper.dart 76:32  IterableHelper.deserialize
package:json_serializable/src/type_helper_ctx.dart 68:29               TypeHelperCtx.deserialize.<fn>
dart:core                                                              Iterable.firstWhere
package:json_serializable/src/type_helper_ctx.dart 88:46               TypeHelperCtx._run
package:json_serializable/src/type_helper_ctx.dart 65:19               TypeHelperCtx.deserialize
package:json_serializable/src/decode_helper.dart 197:10                DecodeHelper._deserializeForField.deserialize
package:json_serializable/src/decode_helper.dart 216:17                DecodeHelper._deserializeForField
package:json_serializable/src/decode_helper.dart 56:9                  DecodeHelper.createFactory.deserializeFun
package:json_serializable/src/decode_helper.dart 314:32                _writeConstructorInvocation.<fn>
dart:core                                                              StringBuffer.writeAll
package:json_serializable/src/decode_helper.dart 312:9                 _writeConstructorInvocation
package:json_serializable/src/decode_helper.dart 59:18                 DecodeHelper.createFactory
package:json_serializable/src/generator_helper.dart 85:28              GeneratorHelper.generate
dart:_internal                                                         WhereIterator.moveNext
package:json_serializable/src/json_part_builder.dart 64:27             _UnifiedGenerator.generate
package:source_gen/src/builder.dart 328:23                             _generate
yousinix commented 2 years ago

I have the same issue too. I had to downgrade json_serializable to ^4.1.2 to get it to work. Seems like the issue exists in v5.X.X too.

mohan-sai-manthri-sg commented 2 years ago

I'm facing this issue in version 6.1.1 and I cannot downgrade to 4.1.2 as there are other depedent packages. Is there any other solution?

kevmoo commented 2 years ago

Published! https://pub.dev/packages/json_serializable/changelog#612