Complex models with json_serializable - List<objects> not converting to map Complex models with json_serializable - List<objects> not converting to map flutter flutter

Complex models with json_serializable - List<objects> not converting to map


After many trials and rebuilds, I have resolved this issue and everything appears to be working now with my Sembast DB using json_serializable for my model classes. Possibly there were other factors that contributed to my success, but I think the main difference was adding the following parameter to the JSONSerializable annotation of the Parent class.

explicitToJson: true

Here is the code, in the event it helps somebody else out there.

The full explanation you can find here https://flutter.dev/docs/development/data-and-backend/json

@JsonSerializable(explicitToJson: true)class Parent {  int id;  final String name;  final int age;  List<Child> children;  Job job;  Parent({this.name, this.age, this.children, this.job});  factory Parent.fromJson(Map<String, dynamic> json) => _$ParentFromJson(json);  Map<String, dynamic> toJson() => _$ParentToJson(this);}