Closed
Description
Before opening, please confirm:
- I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- I have searched for duplicate or closed issues.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
How did you install the Amplify CLI?
npm
If applicable, what version of Node.js are you using?
v14.15.3
Amplify CLI Version
7.6.4
What operating system are you using?
Ubuntu
Amplify Codegen Command
codegen, codegen models
Describe the bug
The generated models code should include toJson&fromJson for normal json(String) instead of using them for (Map).
Also the (Map) class should have toMap&fromMap instead of using toJson&fromJson.
like this:
Map<String, dynamic> toMap() {
return {
'id': id,
'title': title,
'icon': icon,
});
}
factory Course.fromMap(Map<String, dynamic> map) {
return Course(
id: map['id'],
title: map['title'],
icon: map['icon'] ?? '',
);
}
String toJson() => json.encode(toMap());
factory Course.fromJson(String source) => Course.fromMap(json.decode(source));
Expected behavior
Have model like this:
Map<String, dynamic> toMap() {
return {
'id': id,
'title': title,
'icon': icon,
});
}
factory Course.fromMap(Map<String, dynamic> map) {
return Course(
id: map['id'],
title: map['title'],
icon: map['icon'] ?? '',
);
}
String toJson() => json.encode(toMap());
factory Course.fromJson(String source) => Course.fromMap(json.decode(source));
Reproduction steps
- just generate the models
GraphQL schema(s)
# Put schemas below this line
Log output
# Put your logs below this line
Additional information
No response