Aws-sdk-java-v2: DynamoDB Enhanced mapping does not support Date nor ByteBuffer

Created on 15 Oct 2020  路  5Comments  路  Source: aws/aws-sdk-java-v2


While trying to map properties java.nio.ByteBuffer and java.util.Date using DynamoDb Enhanced mapper within Kotlin code, I get an exception.

Describe the bug


The following exceptions occur with both the @DynamoDbBean mapper and the TableSchema.builder:

  • org.springframework.beans.BeanInstantiationException: Failed to instantiate [service.account.Account]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Converter not found for EnhancedType(java.nio.ByteBuffer)
  • org.springframework.beans.BeanInstantiationException: Failed to instantiate [service.account.Account]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Converter not found for EnhancedType(java.util.Date)

Sample Kotlin code:

class Account {
    constructor() {}

    constructor(pKey: String, bb: ByteBuffer?, created: Date?) {
        this.pKey = pKey
        this.byteBuf = bb
        this.created = created
    }

    var pKey: String = ""

    var byteBuf: ByteBuffer? = null

    var created: Date? = null
}

val ACCOUNT_TABLE_SCHEMA: TableSchema<Account> = TableSchema.builder(Account::class.java)
        .newItemSupplier { Account() }
        .addAttribute(String::class.java) { a: StaticAttribute.Builder<Account, String> ->
            a.name("pKey")
                    .getter { obj: Account -> obj.pKey }
                    .setter { obj: Account, d: String -> obj.pKey = d }
                    .tags(StaticAttributeTags.primaryPartitionKey())
        }
// FIXME instantiation error:
// Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate: Constructor threw exception; nested exception is java.lang.IllegalStateException: Converter not found for EnhancedType(java.nio.ByteBuffer)
        .addAttribute(ByteBuffer::class.java) { a: StaticAttribute.Builder<Account, ByteBuffer?> ->
            a.name("byteBuf")
                    .getter { obj: Account -> obj.byteBuf }
                    .setter { obj: Account, d: ByteBuffer? -> obj.byteBuf = d }
        }
// FIXME instantiation error:
        // Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate: Constructor threw exception; nested exception is java.lang.IllegalStateException: Converter not found for EnhancedType(java.util.Date)
        .addAttribute(Date::class.java) { a: StaticAttribute.Builder<Account, Date?> ->
            a.name("created")
                    .getter { obj: Account -> obj.created }
                    .setter { obj: Account, d: Date? -> obj.created = d }

        }
        .build()

Your Environment

  • AWS Java SDK version used: 2.15.7
  • JDK version used: Kotlin 1.4.10 and Java 11
  • Operating System and version: macOS Catalina 10.15.7
dynamodb-enhanced feature-request hacktoberfest kotlin

Most helpful comment

Hi @ceven, thank you for reaching out. Date and ByteBuffer converters are not provided by default. You can use one of the Java types that has an attribute converter provided (you can see a list here) or you can write a custom converter and specify it with a converterProviders annotation. For more details and examples check the DynamoDB Enhanced Client overview.

Let us know if that helps.

All 5 comments

Hi @ceven, thank you for reaching out. Date and ByteBuffer converters are not provided by default. You can use one of the Java types that has an attribute converter provided (you can see a list here) or you can write a custom converter and specify it with a converterProviders annotation. For more details and examples check the DynamoDB Enhanced Client overview.

Let us know if that helps.

Thank you @debora-ito , that's helpful to unblock me!
Is it possible to add this as a feature request? Would be great to have these converters in the SDK.

For ByteBuffer maybe, yes. For Date I believe we have good substitutes like Instant, LocalDate, LocalTime, LocalDateTime, Period, etc.

ByteBufferAttributeConverter was added in SDK version 2.16.35.

Closing this, feel free to reach out if there's any other question.

鈿狅笍COMMENT VISIBILITY WARNING鈿狅笍

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Was this page helpful?
0 / 5 - 0 ratings