diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithydotnet/TypeConversionCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithydotnet/TypeConversionCodegen.java index aa19e7bfe..06a7e2696 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithydotnet/TypeConversionCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithydotnet/TypeConversionCodegen.java @@ -19,6 +19,7 @@ import software.amazon.polymorph.traits.LocalServiceTrait; import software.amazon.polymorph.traits.PositionalTrait; import software.amazon.polymorph.traits.ReferenceTrait; +import software.amazon.polymorph.utils.AwsSdkNameResolverHelpers; import software.amazon.polymorph.utils.DafnyNameResolverHelpers; import software.amazon.polymorph.utils.ModelUtils; import software.amazon.polymorph.utils.Token; @@ -485,15 +486,25 @@ private String generateConstructorArg(final MemberShape memberShape) { public TokenTree generateExtractOptionalMember(final MemberShape memberShape) { final String type = nameResolver.baseTypeForShape(memberShape.getId()); final String varName = nameResolver.variableNameForClassProperty(memberShape); - final String isSetMethod = nameResolver.isSetMethodForStructureMember(memberShape); final String propertyName = nameResolver.classPropertyForStructureMember(memberShape); - return TokenTree.of( + if (AwsSdkNameResolverHelpers.isInAwsSdkNamespace(memberShape.getId())) { + return TokenTree.of( + type, + varName, + "= value.%s != null".formatted(propertyName), + "? value.%s :".formatted(propertyName), + "(%s) null;".formatted(type) + ); + } else { + final String isSetMethod = nameResolver.isSetMethodForStructureMember(memberShape); + return TokenTree.of( type, varName, "= value.%s()".formatted(isSetMethod), "? value.%s :".formatted(propertyName), "(%s) null;".formatted(type) - ); + ); + } } public TypeConverter generateMemberConverter(final MemberShape memberShape) {