Cannot load data from DynamoDB due to an attribute of type List<Object> which is not able to get unconverted and was saved using @DynamoDBDocument

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?

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 {
...
}

A no-args constructer was required to unconvert the attribute, adding @lombok.NoArgsConstructor to the Manufacturer class solved my problem.