- 
  Notifications
 You must be signed in to change notification settings 
- Fork 949
[Enhanced DynamoDb] List<CustomObject> is supported but not Set<CustomObject>? #5128
-
I found that a List for the DynamoDb enhanced client following works, but Set does not:
DynamoDbImmutable(builder = DdbObj.DdbObjBuilder.class)
public class DdbObj {
 @DynamoDbPartitionKey
 private final Integer id;
 private final List<CustomObject> objects;
DynamoDbImmutable(builder = CustomObject.CustomObjectBuilder.class)
public class CustomObject {
 private final Integer value;
TableSchema tableSchema = TableSchema.fromImmutableClass(DdbObj.class);
But the following does not:
DynamoDbImmutable(builder = DdbObj.DdbObjBuilder.class)
public class DdbObj {
 @DynamoDbPartitionKey
 private final Integer id;
 private final Set<CustomObject> objects;
TableSchema tableSchema = TableSchema.fromImmutableClass(DdbObj.class);
I get the error "IllegalStateException Converter not found for CustomObject"
After much time looking into the technical reason why this was it appears the root cause is that DDB Set attributes must be one of the following types: N, S, B see code.
If not for the above Set paramaterized type restriction to ImmutableTableSchema.java, It appears support for conversion for Set custom objects by adding the following:
 if (List.class.equals(rawType)) {
 EnhancedType<?> enhancedType = convertTypeToEnhancedType(parameterizedType.getActualTypeArguments()[0],
 metaTableSchemaCache, attributeConfiguration);
 return EnhancedType.listOf(enhancedType);
 }
 // *************** New Code Here ****************************
 if (Set.class.equals(rawType)) {
 EnhancedType<?> enhancedType = convertTypeToEnhancedType(parameterizedType.getActualTypeArguments()[0],
 metaTableSchemaCache, attributeConfiguration);
 return EnhancedType.setOf(enhancedType);
 }
 // *************** New Code Ends Here ****************************
 if (Map.class.equals(rawType)) {
 EnhancedType<?> enhancedType = convertTypeToEnhancedType(parameterizedType.getActualTypeArguments()[1],
 metaTableSchemaCache, attributeConfiguration);
 return EnhancedType.mapOf(EnhancedType.of(parameterizedType.getActualTypeArguments()[0]),
 enhancedType);
 }
Note: did past search could not find info on set of custom objects. See similar 1, 2
My question is why can Set type not support collections of custom objects if they can be supported for Lists? Can we remove the Set type restriction and add the above changes to support Set?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
I checked this and got the same... If I translate all my Set's to List's, it's fine...
Beta Was this translation helpful? Give feedback.