Skip to content

Generics generation error #252

Closed
Closed
@jaumard

Description

@jaumard

I'm trying to generate a file with generic inside and can't figure how to make it work :/

Here is my file:

import 'package:json_annotation/json_annotation.dart';

part 'paginated_list.g.dart';

@JsonSerializable()
class PaginatedList<T> extends Object with _$PaginatedListSerializerMixin {
  PaginatedList(this.count, this.next, this.previous, this.results);

  int count ;
  String next;
  String previous;
  List<T> results;

  bool hasNext() {
    return next != null && !next.isEmpty;
  }
  factory PaginatedList.fromJson(Map<String, dynamic> json) => _$PaginatedListFromJson(json);
}

And it fails with:

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'paginated_list.dart';

// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************

// Error: Could not generate `fromJson` code for `results` because of type `T`.
//        None of the provided `TypeHelper` instances support the defined type.
//        package:flutter_app/models/paginated_list.dart:20:11
//          List<T> results;
//                  ^^^^^^^
// TODO: Make sure all of the types are serializable.

I'm using:
json_annotation: "^0.2.9"
build_runner: "0.8.10"
json_serializable: "^0.5.8"

Any idea what am I doing wrong ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions