aws-mobile-appsync-sdk-android
aws-mobile-appsync-sdk-android copied to clipboard
Fix generating and parsing enums
Issue #, if available: https://github.com/awslabs/aws-mobile-appsync-sdk-android/issues/349
Description of changes: When somebody will add a new value for any Enum in the schema and will start sending it, apps will older schema will crash. I fixed the code generator to handle empty or unknown Enum values. Fix:
- I added UNKNOWN enum value to every generated enum.
- UKNOWN will be set when the enum value is null (to by safe for kotlin) or some new one.
Old generated code:
final MyEnum something;
if (somethingStr != null) {
something = MyEnum.valueOf(somethingStr);
} else {
something = null;
}
New generated code:
MyEnum something;
if (somethingStr != null) {
try {
something = MyEnum.valueOf(somethingStr);
} catch (IllegalArgumentException exception) {
something = MyEnum.UNKNOWN;
}
} else {
something = MyEnum.UNKNOWN;
}
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.