I have an interface Employee and Department. I'm loading JSON from server that I need to "parse" to object that implements those interfaces. Is there a way how to achieve this automatically since all types in interface and JSON object are base types (String, number, list, map)?
// Abstract classes represents interfaces
abstract class Employee {
String firstName;
String lastName;
}
abstract class Department {
String name;
List<Employee> employees;
}
// JSON
{
"name": "Development",
"employees":
[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]
}
I want to parse it like this
main() {
...
Department department = someMethodToParse(jsonFromServer);
...
}