Reputation: 11
I have an abstract model class that has an abstract function that determines how a widget switches state and I would like to keep it. I am currently trying to implement https://pub.dev/packages/json_serializable but it wants me to switch the field type to a dynamic type instead of my abstract one. You cant @JsonSerializeable abstract classes and when I switch to a dynamic type the print reads as Instance of 'class' even when the concrete implementations have a valid toJson method.
Should I just throw out OOP principle implementation or is there an alternative solution here?
Upvotes: 0
Views: 565
Reputation: 11
<String, dynamic>{
'command': instance.command,
'questions': instance.questions.map((e) {return (e as Question).toJson();}).toList(),
};
Solved by writing my own serializer for my abstract class
Upvotes: 1