AWS DynamoDB: Could not unconvert attribute error AWS DynamoDB: Could not unconvert attribute error json json

AWS DynamoDB: Could not unconvert attribute error


Short answer:

Add a public empty constructor to Media class.

Long answer:

In your code, when you are performing databaseController.get(Product.class, id), your are invoking the underline method public T unconvert(final Map<String,AttributeValue> object) of DynamoDBMapperTableModel:

@Overridepublic T unconvert(final Map<String,AttributeValue> object) {    final T result = StandardBeanProperties.DeclaringReflect.<T>newInstance(targetType);    if (!object.isEmpty()) {        for (final DynamoDBMapperFieldModel<T,Object> field : fields()) {            try {                final AttributeValue value = object.get(field.name());                if (value != null) {                    field.unconvertAndSet(result, value);                }            } catch (final RuntimeException e) {                throw new DynamoDBMappingException(                    targetType.getSimpleName() + "[" + field.name() + "]; could not unconvert attribute", e                );            }        }    }    return result;}

In the first line of this method, a new instance of the table model is being created using reflection (in your case a new instance of Product), and then the new instance's fields are being converted to the desired class and set accordingly.

StandardBeanProperties.DeclaringReflect.<T>newInstance(targetType) invoking .newInstance() on targetType, witch it's type is Class<T>.

As written in Class.newInstance() documentation, InstantiationException is thrown if the class has no nullary constructor. There are other scenarios in which this exception will be thrown but in my experience, it's probably because a public empty constructor is not implemented.


For me it was typo in setter method.

@DynamoDBAttribute(attributeName = "closed_date_time")public Date getClosedDateTime() {    return closedDateTime;}public void setClosedDate(Date closedDateTime) {    this.closedDateTime = closedDateTime;}

I had replaced setClosedDate with setClosedDateTime and then it worked.


Generated the Setter Getter again it works!It was a typo in my case too.

But if DataType of the column was Long and you converted the dataType to String. That can also cause this issue for existing data.