Skip to content

Commit

Permalink
fix(amplify-codegen): fix for non-model decoding in flutter v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Equartey committed May 14, 2024
1 parent 0f3bbe0 commit dc631a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1142,12 +1142,14 @@ class Contact {
Contact.fromJson(Map<String, dynamic> json)
: _contactName = json['contactName'],
_phone = json['phone'] != null
? Phone.fromJson(new Map<String, dynamic>.from(json['phone']))
? json['phone']['serializedData'] != null
? Phone.fromJson(new Map<String, dynamic>.from(json['phone']['serializedData']))
: Phone.fromJson(new Map<String, dynamic>.from(json['phone']))
: null,
_mailingAddresses = json['mailingAddresses'] is List
? (json['mailingAddresses'] as List)
.where((e) => e != null)
.map((e) => Address.fromJson(new Map<String, dynamic>.from(e)))
.map((e) => Address.fromJson(new Map<String, dynamic>.from(e['serializedData'] ?? e)))
.toList()
: null;

Expand Down Expand Up @@ -1390,12 +1392,14 @@ class Person extends amplify_core.Model {
: id = json['id'],
_name = json['name'],
_phone = json['phone'] != null
? Phone.fromJson(new Map<String, dynamic>.from(json['phone']))
? json['phone']['serializedData'] != null
? Phone.fromJson(new Map<String, dynamic>.from(json['phone']['serializedData']))
: Phone.fromJson(new Map<String, dynamic>.from(json['phone']))
: null,
_mailingAddresses = json['mailingAddresses'] is List
? (json['mailingAddresses'] as List)
.where((e) => e != null)
.map((e) => Address.fromJson(new Map<String, dynamic>.from(e)))
.map((e) => Address.fromJson(new Map<String, dynamic>.from(e['serializedData'] ?? e)))
.toList()
: null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,9 @@ export class AppSyncModelDartVisitor<
`${fieldName} = json['${varName}'] is List`,
indent(`? (json['${varName}'] as List)`),
indent(`.where((e) => e != null)`, 2),
indent(`.map((e) => ${this.getNativeType({ ...field, isList: false })}.fromJson(new Map<String, dynamic>.from(e)))`, 2),
indent(`.map((e) => ${this.getNativeType({ ...field, isList: false })}.fromJson(new Map<String, dynamic>.from(${
this.isNonModelType(field) ? "e['serializedData'] ?? e" : 'e'
})))`, 2),
indent(`.toList()`, 2),
indent(`: null`),
]
Expand All @@ -756,8 +758,10 @@ export class AppSyncModelDartVisitor<
// single non-model i.e. embedded
return [
`${fieldName} = json['${varName}'] != null`,
indent(`? ${this.getNativeType(field)}.fromJson(new Map<String, dynamic>.from(json['${varName}']))`),
indent(`: null`),
indent(`? json['${varName}']['serializedData'] != null`, 2),
indent(`? ${this.getNativeType(field)}.fromJson(new Map<String, dynamic>.from(json['${varName}']['serializedData']))`, 4),
indent(`: ${this.getNativeType(field)}.fromJson(new Map<String, dynamic>.from(json['${varName}']))`, 4),
indent(`: null`,),
].join('\n');
}
//regular type
Expand Down

0 comments on commit dc631a7

Please sign in to comment.