from backend I'm receiving json that looks like this
{
"teamDto": {
"id": "34ec8e71-b5a9-4a4c-b461-5cbb562329b5",
"teamName": "tasdasd",
"payPerPractice": 123.0,
"payPerGame": 123.0,
"season": "asdasd",
"teamMembers": [
{
"id": "4657dd50-974c-427c-8e77-0f5e1f4fd23c",
"isOwner": true,
"isManager": true,
"teamName": "tasdasd",
"teamId": "34ec8e71-b5a9-4a4c-b461-5cbb562329b5",
"name": null,
"lastName": null
},
{
"id": "6a758edd-fbac-49b5-bed4-250c585b5c3f",
"isOwner": false,
"isManager": false,
"teamName": "tasdasd",
"teamId": "34ec8e71-b5a9-4a4c-b461-5cbb562329b5",
"name": null,
"lastName": null
},
{
"id": "98786a8a-3915-4e3a-b832-32fc6c4d8b8d",
"isOwner": true,
"isManager": true,
"teamName": "tasdasd",
"teamId": "34ec8e71-b5a9-4a4c-b461-5cbb562329b5",
"name": null,
"lastName": null
},
{
"id": "c3e76455-a7bb-4be4-abe7-09436f6fe3df",
"isOwner": false,
"isManager": false,
"teamName": "tasdasd",
"teamId": "34ec8e71-b5a9-4a4c-b461-5cbb562329b5",
"name": null,
"lastName": null
}
],
"sport": null
},
"owner": true,
"manager": true
}
I'm aware of imperfections in my json, but thats not the problem. The problem is when i try to convert it to object, my programm throws stackoverflow. Here is my TeamDashboardDtoclass
class TeamDashboardDto{
late TeamDto teamDto;
late bool isOwner;
late bool isManager;
TeamDashboardDto({required this.teamDto, required this.isOwner, required this.isManager});
factory TeamDashboardDto.fromJson(Map<String, dynamic> json) => TeamDashboardDto.fromJson(json);
Map<String, dynamic> toJson() => UserAndTeamDtoToJson(this);
Map<String, dynamic> UserAndTeamDtoToJson(TeamDashboardDto instance) => <String, dynamic>{
'teamDto': instance.teamDto,
'owner': instance.isOwner,
'manager': instance.isManager,
};
}
and here is my TeamDto class
class TeamDto{
String? id;
String? teamName;
double? payPerPractice;
double? payPerGame;
String? season;
List<TeamMemberDto>? teamMembers;
TeamDto({this.id, this.teamName, this.payPerGame, this.payPerPractice, this.season, this.teamMembers});
factory TeamDto.fromJson(Map<String, dynamic> json) {
return TeamDto(
id: json['id'],
teamName: json['teamName'],
payPerPractice: json['payPerPractice'],
payPerGame: json['payPerGame'],
season: json['season'],
teamMembers: List<TeamMemberDto>.from(
json['teamMembers'].map((model) => TeamMemberDto.fromJson(model)))
);
}
Map<String, dynamic> toJson() => {
'id': id,
'teamName': teamName,
'sport': sport,
'payPerGame': payPerGame,
"payPerPractice": payPerPractice,
"season": season,
"teamMembers": teamMembers
};
}
I dont see why theres a problem because i have other Dto classes that contain two different dto's which one of them is TeamDto, the only difference here is that this dto class contains two booleans and another dto class instead of two dto classes.