I have dart web app using sdk 1.24 and have been using dson: 0.11.0 to generate serializable classes/models for my objects that are being saved to a firestore database.
I love the way the dson generated classes give me the ability to create a dart object from a map, or serialize a dart object to a map for saving in firebase.
With that said, the dson generator requires my model class to extend a serializable abstract generated class.
My application is starting to grow rather large and I am struggling with the inability to use inheritance and develop a class hierarchy.
Unless I am missing some concept that I can't seem to crack on my own, I cannot figure out how to use class inheritance with the dson generator.
For example, here is a really simple example of what I am trying to do.
class EmploymentIncome extends Object {
String employerName;
Address employerAddress;
DateTime hireDate;
}
class SalaryIncome extends EmploymentIncome {
double annualSalary;
}
class HourlyIncome extends EmploymentIncome {
double hourlyRate;
double hoursPerWeek;
}
class hourlyPaystub extends HourlyIncome {
double yearToDateHourlyEarnings;
double hoursWorked;
DateTime payDate;
DateTime periodEndingDate;
}
class salaryPaystub extends SalaryIncome {
double yearToDateSalaryEarnings;
DateTime payDate;
DateTime periodEndingDate;
}
The problem is, the dson generator requires my models to extend the generated abstract class, see below:
@serializable
class EmploymentIncome extends _$EmploymentIncomeSerializable {
class EmploymentIncome extends Object {
String employerName;
Address employerAddress;
DateTime hireDate;
}
The problem, obviously, is now, I cannot extend EmploymentIncome with another serializable dson class.
Am I missing a fundamental concept or technique that would allow me to extend these classes while still maintaining the ability to convert dart objects to and from maps?
Thank you in advance for any guidance!