I am trying to create a Model
and using json_serializable
package in Flutter
but the issue I am facing is when I try to serialize or auto-generate code for the class that is extending base class.
So in below class if i remove AuthResponseData
it is throwing following error
Could not generate
fromJson
code foruser
.
late final UserData user;
For example,
@JsonSerializable()
class AuthResponseDataModel extends AuthResponseData {
final UserDataModel user;
final AccountDataModel accountData;
AuthResponseDataModel(
this.user,
this.accountData,
);
factory AuthResponseDataModel.fromJson(Map<String, dynamic> json) =>
_$AuthResponseDataModelFromJson(json);
Map<String, dynamic> toJson() => _$AuthResponseDataModelToJson(this);
}
This is my entity class AuthResponseData
class AuthResponseData extends Equatable {
late final UserData user;
late final AccountData accountData;
late final List<String> permissions;
AuthResponseData({user, accountData, permissions});
@override
List<Object?> get props => [user, accountData, permissions];
}
Eventually, I want to typecase AuthResponseDataModel
to AuthResponse
but json_serializer is not allowing me to do so