gemini-code-assist[bot] commented on code in PR #37347:
URL: https://github.com/apache/beam/pull/37347#discussion_r2988140051
##########
sdks/java/io/amazon-web-services2/src/main/java/org/apache/beam/sdk/io/aws2/schemas/AwsTypes.java:
##########
@@ -91,6 +93,20 @@ private static FieldType fieldType(SdkField<?> field,
Set<Class<?>> seen) {
String.format("Type %s of field %s is unknown.", type,
normalizedNameOf(field)));
}
+ static FieldValueTypeInformation fieldValueTypeInformationFor(SdkField<?>
sdkField) {
+ TypeDescriptor<?> type =
TypeDescriptor.of(sdkField.marshallingType().getTargetClass());
+ return FieldValueTypeInformation.builder()
+ .setName(normalizedNameOf(sdkField))
+ .setType(type)
+ .setRawType(sdkField.marshallingType().getClass())
+
.setElementType(FieldValueTypeInformation.getIterableComponentType(type))
+ .setMapKeyType(FieldValueTypeInformation.getMapKeyType(type))
+ .setMapValueType(FieldValueTypeInformation.getMapValueType(type))
+ .setOneOfTypes(Collections.emptyMap())
+ .setNullable(true)
+ .build();
+ }
Review Comment:

The implementation of `fieldValueTypeInformationFor` appears to not fully
handle generic types for collections and maps within AWS SDK objects.
Using `TypeDescriptor.of(sdkField.marshallingType().getTargetClass())` will
lose generic type parameters. For example, for a `List<String>`,
`getTargetClass()` returns `List.class`, and `TypeDescriptor.of(List.class)`
does not retain the `String` element type. This means
`FieldValueTypeInformation.getIterableComponentType(type)` will likely resolve
to `Object`.
To correctly support collections and maps, you could inspect
`sdkField.marshallingType()`. If it's a list or map, you can recursively
determine the component types, similar to how the `fieldType` method in this
class does it using `MarshallingInfo.MEMBER_MARSHALLING_TYPE`.
For instance, for lists, you could do something like:
```java
if (sdkField.marshallingType() == MarshallingType.LIST) {
MarshallingType<?> memberMarshallingType =
sdkField.getMemberProperty(MarshallingInfo.MEMBER_MARSHALLING_TYPE);
// ... use memberMarshallingType to get element type information
}
```
This would provide more accurate type information, aligning better with the
overall goal of this pull request to improve generics support.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]