I'm trying to add a binary set attribute to my DynamoDb Table. Each element in the set is an InternalImage proto.
@DynamoDBAttribute
@DynamoDBTypeConverted(converter = Converters.InternalImagesConverter::class)
var image_assets: Set<InternalImage>? = null
class InternalImagesConverter : DynamoDBTypeConverter<Set<ByteString>, Set<InternalImage>> {
override fun convert(input: Set<InternalImage>?): Set<ByteString>? =
input?.map { it.encodeByteString() }?.toSet()
override fun unconvert(input: Set<ByteString>?): Set<InternalImage>? =
input?.map { InternalImage.ADAPTER.decode(it) }?.toSet()
}
I get the following error when I try to access any element within unconvert:
ClassCastException: class java.lang.String cannot be cast to class okio.ByteString
Digging into this, it looks like DynamoDbMapper casts my ByteString into a String because the attributeType of my field is set to SS or "String Set" instead of "Binary Set". So, I tried specifying the type by adding an annotation.
@DynamoDBAttribute
@DynamoDBTyped(value = DynamoDBMapperFieldModel.DynamoDBAttributeType.BS)
@DynamoDBTypeConverted(converter = Converters.InternalImagesConverter::class)
var image_assets: Set<InternalImage>? = null
Error:
DynamoDBMappingException: ServiceItem[image_assets] could not be mapped for type Set<Object>
DynamoDBMappingException: type [class java.lang.Object] is not supported; no conversion from class java.nio.ByteBuffer
I've tried using ByteArray and ByteBuffer. I've also tried changing my converter to convert just ByteString/ByteArray/ByteBuffer to InternalImage thinking that maybe DynamoDbMapper handles the set part. All resulted in a similar error.
Has anyone successfully set up a binary set attribute in DynamoDb before? I'm not sure what else to try.