2

首先,正确运行的代码: DynamoDB 表中的内容是:

"test_field" : "x:x:x"

实体 POJO 具有:

@DynamoDBTypeConverted(converter = SingleFieldConverter.class)
@DynamoDBAttribute(attributeName = "test_field")
private SingleField singleField;

使用适当的 getter 和 setter 方法。转换器类是:

public class SingleFieldConverter implements DynamoDBTypeConverter<String, SingleField> {

@Override
public String convert(SingleField singleField) {
   // removed for clarity
}

@Override
public SingleField unconvert(String s) {
   // removed for clarity
}

它有效!

但是当我将 DynamoDB 项目更改为:

"test_field" : [
        "x:x:x",
        "x:x:x"
        ]
      

和我的 POJO 对象:

@DynamoDBTypeConverted(converter = SingleFieldConverter.class)
@DynamoDBAttribute(attributeName = "test_field")
private List<SingleField> singleField;

和转换器类是这样的:

public class SingleFieldConverter implements DynamoDBTypeConverter<String, List<SingleField>> {

@Override
public String convert(List<SingleField> singleField) {
   // removed for clarity
}

@Override
public List<SingleField> unconvert(String s) {
   // removed for clarity
}

}

它抛出:

DynamoDBMappingException
. . . . . [test_field]; could not unconvert attribute
 . . .Caused by: com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException: expected S in value {L: [{S: x:x:x:,}, {S: x:x:x:,}],}

我在网上找到的类似示例据称有效,但我的示例无效。我错过了什么,请帮忙?

4

0 回答 0