Suppose I have the following json (structured as <String key, Map value>):
{
'A1': {'name': 'a'},
'B2': {'name': 'b'}
}
and I want to parse it to this class (notice that I use the key as the id for that user), using the fromJson factory method, which accepts two arguments:
Class User {
final String id;
final String name;
factory User.fromJson(Map<String, dynamic> json, String key) {
return User(
id: key,
name: json['name'],
);
}
}
Can I achieve it using json_serializable ?