Closed
Description
Is it possible to use jsonkey to generate a line like this firstName: json ['customKey']['firstName'] as String,
Let's say I have an object like this from the server.
{
customKey : { firstName: ' MyFirstName'
lastName: 'MyLastName'
},
dateOfBirth: '1997-12-17T03:24:00'
}
And I want to create a Flutter Class like this
@JsonSerializable(nullable: false)
class Person {
final String firstName;
final String lastName;
final DateTime dateOfBirth;
Person({this.firstName, this.lastName, this.dateOfBirth});
factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);
Map<String, dynamic> toJson() => _$PersonToJson(this);
}
Person _$PersonFromJson(Map<String, dynamic> json) {
return Person(
**firstName: json['customKey']['firstName'] as String,**
**lastName: json['customKey']['lastName'] as String,**
dateOfBirth: DateTime.parse(json['dateOfBirth'] as String),
);
}
Map<String, dynamic> _$PersonToJson(Person instance) => <String, dynamic>{
'firstName': instance.firstName,
'lastName': instance.lastName,
'dateOfBirth': instance.dateOfBirth.toIso8601String(),
};
Metadata
Metadata
Assignees
Labels
No labels