DynamoDB Enhanced mapping does not support Date nor ByteBuffer
See original GitHub issueWhile 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 Java11
- Operating System and version: macOS Catalina
10.15.7
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
For ByteBuffer maybe, yes. For Date I believe we have good substitutes like Instant, LocalDate, LocalTime, LocalDateTime, Period, etc.