-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(flutter/datastore): Nullable custom type arrays
Fixes aws-amplify/amplify-flutter#3575. When a custom type array is not required and `null` is returned from AppSync, deserialization will fail since `getAsJsonArray` will throw for `null` values. This resolves the issue by checking if a field is `null` before attempting deserialization.
- Loading branch information
Dillon Nys
committed
Aug 18, 2023
1 parent
8020948
commit cd0025e
Showing
5 changed files
with
64 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,7 @@ public void setup() { | |
GsonTemporalAdapters.register(builder); | ||
SerializedModelAdapter.register(builder); | ||
SerializedCustomTypeAdapter.register(builder); | ||
gson = builder.create(); | ||
gson = builder.serializeNulls().create(); | ||
} | ||
|
||
/** | ||
|
@@ -162,6 +162,7 @@ public void serdeForNestedCustomTypes() throws JSONException, AmplifyException { | |
contactSerializedData.put("email", "[email protected]"); | ||
contactSerializedData.put("phone", phone); | ||
contactSerializedData.put("additionalPhoneNumbers", additionalPhoneNumbers); | ||
contactSerializedData.put("aliases", null); | ||
SerializedCustomType contact = SerializedCustomType.builder() | ||
.serializedData(contactSerializedData) | ||
.customTypeSchema(contactSchema) | ||
|
@@ -170,6 +171,7 @@ public void serdeForNestedCustomTypes() throws JSONException, AmplifyException { | |
Map<String, Object> personSerializedData = new HashMap<>(); | ||
personSerializedData.put("fullName", "Tester Test"); | ||
personSerializedData.put("contact", contact); | ||
personSerializedData.put("additionalContacts", null); | ||
personSerializedData.put("id", "some-unique-id"); | ||
SerializedModel person = SerializedModel.builder() | ||
.modelSchema(personSchema) | ||
|
@@ -327,6 +329,14 @@ private CustomTypeSchema customTypeSchemaForContact() { | |
.isArray(true) | ||
.isRequired(true) | ||
.build()); | ||
contactFields.put("aliases", CustomTypeField.builder() | ||
.name("aliases") | ||
.targetType("Contact") | ||
.javaClassForValue(Map.class) | ||
.isCustomType(true) | ||
.isArray(true) | ||
.isRequired(false) | ||
.build()); | ||
return CustomTypeSchema.builder() | ||
.name("Contact") | ||
.pluralName("Contacts") | ||
|
@@ -355,6 +365,14 @@ private ModelSchema modelSchemaForPerson() { | |
.isRequired(true) | ||
.isCustomType(true) | ||
.build()); | ||
personFields.put("additionalContacts", ModelField.builder() | ||
.name("additionalContacts") | ||
.targetType("Contact") | ||
.javaClassForValue(Map.class) | ||
.isRequired(false) | ||
.isCustomType(true) | ||
.isArray(true) | ||
.build()); | ||
return ModelSchema.builder() | ||
.name("Person") | ||
.pluralName("People") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters