question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DynamoDB Enhanced mapping does not support Date nor ByteBuffer

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
debora-itocommented, Oct 16, 2020

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.

2reactions
debora-itocommented, Oct 19, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Supported data types for DynamoDB Mapper for Java
Supported data types for DynamoDB Mapper for Java ; Boolean, BOOL (Boolean type), 0 or 1. ; ByteBuffer, B (binary type) ; Date,...
Read more >
Best approach to handle Java8 date and time in DynamoDB
It's going to depend on your use case so there's no hard and fast "best" approach. However, there are a few considerations to...
Read more >
DynamoDB Enhanced Client for Java: Missing Setters Cause ...
Solution. Make sure every DynamoDB attribute on your entity has a publicly-accessible setter with the same name (case-sensitive) as the getter.
Read more >
Custom Codecs | Scylla Docs
Ability to map CQL timestamp, date and time columns to Java 8 or Joda Time ... Your codecs should be fast: do not...
Read more >
DynamoDB Best Practices - Packt Hub
We will perform this recipe using Java libraries. So the prerequisite is that you should have performed recipes, which use the AWS SDK...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found