I am trying to save datetime as Date to dynamoDB but for some reason it is being saved as string. I checked on the documentation and Date is a supported datatype.
Because of this, when I am trying to scan my table, I am getting an error saying time cannot be unconverted
public class func{
private static final Logger LOGGER = LoggerFactory.getLogger(func.class);
private AmazonDynamoDB dynamoDB = AmazonDynamoDBClientBuilder.defaultClient();
DynamoDBMapper mapper =new DynamoDBMapper(dynamoDB);
private boolean addData(MyClass myClass){
try{
mapper.save(MyClass);
return true;
} catch (Exception ex) {
LOGGER.error("error: {}", ex.getMessage());
}
return false;
}
public List<MyClass> getAll() {
List<MyClass> list = new ArrayList<>();
try{
list = mapper.scan(MyClass.class, new DynamoDBScanExpression());
return list;
}catch (Exception ex){
LOGGER.error("Fetching error: {}", ex.getMessage());
}
return list;
}
}
@DynamoDBTable(tableName = "table")
public class MyClass {
@DynamoDBHashKey(attributeName="id")
public String id;
@DynamoDBAttribute(attributeName="create_time")
public Date createTime;
public void setCreateTime(Date createTime){ this.createTime = createTime;}
public Date getCreateTime(){ return this.createTime; }
}
OOPS: Sorry. Forgot to read entire document. Seems like Date is of String type https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBMapper.DataTypes.html
How can I overcome the error when I am trying to scan through the table?