Closed lucasdidur closed 1 year ago
You must annotate the field – annotating the constructor param is not supported.
Yes, I did @kevmoo , here my class
Class
@JsonSerializable()
class UsuarioModel extends Usuario {
UsuarioModel({
@JsonKey(name: 'name') required String nome,
@JsonKey(name: 'rf') required String rf,
}) : super(
nome: nome,
rf: rf,
);
factory UsuarioModel.fromJson(Map<String, dynamic> json) => _$UsuarioModelFromJson(json);
Map<String, dynamic> toJson() => _$UsuarioModelToJson(this);
}
Generated file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: implicit_dynamic_parameter
part of 'usuario.model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
UsuarioModel _$UsuarioModelFromJson(Map<String, dynamic> json) => UsuarioModel(
nome: json['nome'] as String,
rf: json['rf'] as String,
);
Map<String, dynamic> _$UsuarioModelToJson(UsuarioModel instance) =>
<String, dynamic>{
'nome': instance.nome,
'rf': instance.rf,
};
Hello,
I'm using the last version of json_serialzable, and create a class to map json keys with variables, but the json key ignores the value to generate the code
Aways generates the variable name to parse inside of .g.dart file