I was updating one of our DynamoDB entities with new attributes.
One of the new attribute is called isEnabled
which is of type of String
.
It isn’t getting stored in DynamoDB.
This is an example of the entity object:
@NoArgConstructor
@DynamoDbBean
@DynamoDbTableName(tableName = "tableName")
data class DynamoEntity (
@get:DynamoDbAttribute("isEnabled")
var isEnabled: String;
)
...
If I change the type to Boolean
it works.
If I update the attribute name like so, it also works:
@NoArgConstructor
@DynamoDbBean
@DynamoDbTableName(tableName = "tableName")
data class DynamoEntity (
@get:DynamoDbAttribute("isEnabled")
var enabled: String;
)
...
I couldn't find any documentation around this and if the attribute name starting with is
is an issue.
Is this expected behaviour?
DynamoDbBean
should only be used for a class that conforms to the JavaBeans specification (also mentioned here) & your class doesn't.
As per the spec (8.3.1 Simple properties), the getter for a non-boolean property should be prefixed with get
and is
is only allowed as an extra prefix for boolean
properties. That's why it works when you change the datatype to boolean
and stops working when you change it back to string
.
The enhanced client most likely uses reflection to infer the attribute names and values from the getter and setter methods, and to invoke those methods when reading or writing data to DynamoDB - not adhering to the spec is causing an issue for that process.
Either:
boolean
get
, as per the JavaBeans specificationAttributeConverterProvider
implementation (example)