Skip to content

Rewrote generated copiers to support builders for arbitrarily nested containers. #2423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2021

Conversation

millems
Copy link
Contributor

@millems millems commented Apr 19, 2021

This fixes an issue where DynamoDB types like BatchGetResponse.Builder could not be serialized using
a bean-based serializer, because it contained a Map<K, List<Map<K2, V>>.

@millems millems force-pushed the millem/complex-types-serialization-fix-2 branch 5 times, most recently from 82bbd76 to 33e509f Compare April 20, 2021 18:27
Comment on lines +515 to +519
<exclude>*.SubscribeToShardEvent$BuilderImpl</exclude>
<exclude>*.ConfigurationEvent$BuilderImpl</exclude>
<exclude>*.IntentResultEvent$BuilderImpl</exclude>
<exclude>*.TextResponseEvent$BuilderImpl</exclude>
<exclude>*.IntentResultEvent$BuilderImpl</exclude>
Copy link
Contributor Author

@millems millems Apr 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bean-style getter return type had to be changed.

Comment on lines -173 to -226
if (memberModel.hasBuilder()) {
TypeName builderName = poetExtensions.getModelClass(memberModel.getC2jShape()).nestedClass("BuilderImpl");
return ParameterSpec.builder(builderName, fieldName()).build();
}

if (memberModel.isList()) {
if (memberModel.isCollectionWithNestedBuilderMember()) {
MapModel nestedMapModel = memberModel.getListModel().getListMemberModel().getMapModel();
TypeName nestedMapKeyType = typeProvider.getTypeNameForSimpleType(nestedMapModel.getKeyModel()
.getVariable()
.getVariableType());
ClassName nestedMapValueType = poetExtensions.getModelClass(nestedMapModel.getValueModel().getC2jShape());
TypeName nestedMapReturnType = ParameterizedTypeName.get(ClassName.get(Map.class),
nestedMapKeyType,
nestedMapValueType.nestedClass("BuilderImpl"));
TypeName listType = ParameterizedTypeName.get(ClassName.get(Collection.class), nestedMapReturnType);
return ParameterSpec.builder(listType, fieldName()).build();
}

MemberModel listMember = memberModel.getListModel().getListMemberModel();

if (hasBuilder(listMember)) {
TypeName memberName = poetExtensions.getModelClass(listMember.getC2jShape()).nestedClass("BuilderImpl");
TypeName listType = ParameterizedTypeName.get(ClassName.get(Collection.class), memberName);
return ParameterSpec.builder(listType, fieldName()).build();
} else if (listMember.isSdkBytesType()) {
TypeName listType = ParameterizedTypeName.get(Collection.class, ByteBuffer.class);
return ParameterSpec.builder(listType, fieldName()).build();
}
}

if (memberModel.isMap()) {
MemberModel keyModel = memberModel.getMapModel().getKeyModel();
TypeName keyType = typeProvider.getTypeNameForSimpleType(keyModel.getVariable().getVariableType());
MemberModel valueModel = memberModel.getMapModel().getValueModel();
TypeName valueType = null;

if (hasBuilder(valueModel)) {
valueType = poetExtensions.getModelClass(valueModel.getC2jShape()).nestedClass("BuilderImpl");
} else if (valueModel.isSdkBytesType()) {
valueType = TypeName.get(ByteBuffer.class);
}

if (valueType != null) {
TypeName mapType = ParameterizedTypeName.get(ClassName.get(Map.class), keyType, valueType);
return ParameterSpec.builder(mapType, fieldName()).build();
}
}

if (memberModel.isSdkBytesType()) {
return ParameterSpec.builder(ByteBuffer.class, fieldName()).build();
}

return memberAsParameter();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for removing this!

@@ -482,4 +350,17 @@ private String memberParamName() {
}
return Utils.unCapitalize(memberModel.getC2jShape()) + "Param";
}

private static final class VariableSource {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class name is too generic for me, I'd prefer if it was renamed to be more specific to its task.
IDK if I love disambiguator but it's the only think I can think of now :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think of a better name. It provides unique variable names... UniqueVariableSource? VariableUniquifier?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UniqueVariableSource is better than VariableSource

NONE
}

public static final class TypeNameOptions {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class makes it much easier to reason around how to build types

…containers.

This fixes an issue where DynamoDB types like BatchGetResponse.Builder could not be serialized using
a bean-based serializer, because it contained a Map<K, List<Map<K2, V>>.
@millems millems force-pushed the millem/complex-types-serialization-fix-2 branch from b352025 to 0dfee39 Compare April 21, 2021 20:15
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

94.4% 94.4% Coverage
0.0% 0.0% Duplication

@millems millems merged commit 06d23db into master Apr 21, 2021
@millems millems deleted the millem/complex-types-serialization-fix-2 branch April 21, 2021 21:38
aws-sdk-java-automation added a commit that referenced this pull request Mar 17, 2023
…ed10593a8

Pull request: release <- staging/4849877e-99ce-403a-ad32-ac2ed10593a8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants