Skip to content

JsonSerializable: generate valid lists in strong mode  #104

@johnpryan

Description

@johnpryan

Currently, lists will generate a constructor like this:

// source
class User extends Object with _$UserSerializerMixin {
  List<int> tags;
  User(this.tags);
  factory User.fromJson(Map json) => _$UserFromJson(json);
}

// generated
User _$UserFromJson(Map json) => new User(
(json['tags'] as List)?.map((v0) => v0)?.toList());

Which generates the following strong-mode error:

WARNING: Unsafe implicit cast from 'List<dynamic>' to 'List<int>'. This usually indicates that type information was lost and resulted in 'dynamic' and/or a place that will have a failure at runtime. ([revolution] lib/model.g.dart:725)

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