I am trying to save a List<CustomObject>
using the @DynamoDBDocument but it gives me a DynamoDBMappingException : could not unconvert attribute.
Here is what my Entity class looks like -
@lombok.Data
@DynamoDBTable(tableName = "carTable")
public class Car {
@DynamoDBHashKey(attributeName = "name")
private carName;
@DynamoDBRangeKey(attributeName = "model")
private carModel;
@DynamoDBAttribute(attributeName = "manufacturers")
private List<Manufacturer> manufacturers;
}
The Manufacturer class looks like -
@lombok.Data
@DynamoDBDocument
public class Manufacturer {
@DynamoDBAttribute
private String manufacturerName;
}
When using this entity and saving the values into the table it saves properly as JSON, but when retrieving it, an exception is thrown -
com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException: Car[manufacturers]; could not unconvert attribute
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperTableModel.unconvert(DynamoDBMapperTableModel.java:271)
[junit] at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.privateMarshallIntoObject(DynamoDBMapper.java:456)
[junit] at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.load(DynamoDBMapper.java:422)
[junit] at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.load(DynamoDBMapper.java:433)
[junit] at com.amazonaws.services.dynamodbv2.datamodeling.AbstractDynamoDBMapper.load(AbstractDynamoDBMapper.java:85)
What am I missing here, do I need to add some sort of TypeConverter or Marshaller here?
Unlike conventional relational databases, DynamoDB does not natively support a date and time data type.
In Amazon DynamoDB, an item is a collection of attributes. Each attribute has a name and a value. An attribute value can be a scalar, a set, or a document type. For more information, see Amazon DynamoDB: How it works. DynamoDB provides four operations for basic create, read, update, and delete (CRUD) functionality.
DynamoDB uses three basic data model units, Tables, Items, and Attributes. Tables are collections of Items, and Items are collections of Attributes. Attributes are basic units of information, like key-value pairs.
DynamoDB has support for storing complex data types like lists, sets or maps (aka dictionaries/hash tables). This capability allows for flexible usage patterns.
A no-args constructer was required to unconvert the attribute, adding @lombok.NoArgsConstructor to the Manufacturer class solved my problem.
I don't think you need a custom converter here, it looks like that DynamoDB has some issues with converting DynamoDB item into a Java object.
Check:
Data in DynamoDB matches your object fields. Check if types are matching as well
What if you define setters explicitly? Maybe Lombok is a culprit here?
Also it is odd that you do not specify a table name here:
@DynamoDBTable(tableName)
public class Car {
...
}
In my case, the issue was that the setters were missing
This was because I was using Lombok with @Builder and @Getter annotations only
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With