DynamoDB ehnchant client mappers annotations can be applied only to methods, not to fields.
This make it hard (or event create) data classes in Kotlin which are perfect to represent DDB model classes.
I'm working on a Kotlin project using DDB enhanced client mappers.
When we worked with v1 we could have created model classes like this:
https://gist.github.com/yairzaslavsky/486a66871c57bf23629a812320abf697
But now, that we want to use the enhanced client , we cannot create data classes, as we the annotations can be applied only to methods.
This ended up with us creating code like this:
https://gist.github.com/yairzaslavsky/8cc4e87ff83425b492522d2bcdb70f04
I would expect to have the ability to implement a data class like in the first link.
At the moment i cannot implement a data class this way, as i have to override the getter behavior
You can use the above links as example
Change the annotations to to be applied to fields as well.
I am developing a server side component using Kotlin that uses DDB.
Hi @yairzaslavsky thank you for your interest in the DynamoDB Enhanced Client.
We understand the issue but applying annotations in the methods is by design. I'm changing this to a feature request to support Kotlin specific implementations.
If anyone wants to show support for this feature please thumbs up 馃憤 the original post to help us with prioritization.
Thank you Deborah.
Glad I found this issue, new to Kotlin and didn't understand why it wasn't working, nothing specific was pointing me to the dynamodb annotations
@drissamri i saw you thumbed up, you are supposed to thumb up the original post. Thanks for showing interest in this.
@yairzaslavsky
can't you do this?
@DynamoDbBean
data class Person(
@get:DynamoDbPartitionKey
var personId: String,
@get:DynamoDbAttribute(value = "name")
var name: String,
@get:DynamoDbSecondaryPartitionKey(indexNames = ["familyName-index"])
var familyName: String,
@get:DynamoDbAttribute(value = "createTime")
var createTime: Long = java.time.Instant.now().epochSecond,
@get:DynamoDbAttribute(value = "updateTime")
var updateTime: Long = java.time.Instant.now().epochSecond
)
?
This is related to, or possible duplicate of, #2096
Most helpful comment
Hi @yairzaslavsky thank you for your interest in the DynamoDB Enhanced Client.
We understand the issue but applying annotations in the methods is by design. I'm changing this to a feature request to support Kotlin specific implementations.
If anyone wants to show support for this feature please thumbs up 馃憤 the original post to help us with prioritization.