Json_serializable.dart: @JsonKey(fromJson) Arguments of a constant creation must be constant expressions.

Created on 22 Feb 2019  路  1Comment  路  Source: google/json_serializable.dart

I'm trying to use @JsonKey(fromJson: (j)=>j) to make the entire json map available as a field. I get the error Arguments of a constant creation must be constant expressions.

Am I doing something wrong? Or has there been an API change?

@JsonSerializable(createToJson: false)
class Entry {
  final int id;

  @JsonKey(fromJson: _dataFromJson)
  final Map<String, dynamic> data;

  Entry(this.id, this.data);

  _dataFromJson(Map<String, dynamic> input) => input;

  factory Entry.fromJson(Map<String, dynamic> json) => _$EntryFromJson(json);
}

screen shot 2019-02-22 at 2 09 41 pm

Most helpful comment

Ah, its gotta be a static member.

>All comments

Ah, its gotta be a static member.

Was this page helpful?
0 / 5 - 0 ratings