DynamoDBMapper - Невозможно создать набор строк - PullRequest
1 голос
/ 09 мая 2020

Я использую DynamoDBMapper для моделирования и сохранения своих объектов в DynamoDB. У меня есть простая сущность с несколькими свойствами, включая одно, которое должно быть java.util.Set из java.lang.String объектов. Однако, когда я запрашиваю создание таблицы, я вижу следующее предупреждение:

WARN  [com.amazonaws.services.dynamodbv2.datamodeling.StandardModelFactories] Marshaling a set of non-String objects to a DynamoDB StringSet. You won't be able to read these objects back out of DynamoDB unless you REALLY know what you're doing: it's probably a bug. If you DO know what you're doing feelfree to ignore this warning, but consider using a custom marshaler for this instead.

Если я попытаюсь добавить значение в это свойство, а затем сохраните свою сущность, я получу следующее исключение:

com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: One or more parameter values were invalid: An string set  may not be empty (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: a6ada7e0-ea45-4826-bff3-78ebbaf6c399)

В документации DynamoDBMapper четко указано, что Set s из String s поддерживаются. Моя сущность выглядит примерно так:

@DynamoDBTable(tableName = Constants.TABLE_NAME)
public class ItemRecord implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = -554992528076340433L;

    @DynamoDBAttribute
    private String creatorIdentifier = null;

    @DynamoDBTyped(DynamoDBAttributeType.SS)
    private Set<String> itemIdentifiers = new HashSet<>();

    // (More attributes here, including partition and range keys)
    ...
}

А мой код создания таблицы выглядит примерно так:

ArrayList<AttributeDefinition> attrs = new ArrayList<>();
attrs.add(new AttributeDefinition().withAttributeName("pk").withAttributeType(ScalarAttributeType.S));
attrs.add(new AttributeDefinition().withAttributeName("sk").withAttributeType(ScalarAttributeType.S));

GlobalSecondaryIndex reverseIndex = new GlobalSecondaryIndex().withIndexName(Constants.GSI_REVERSE_INDEX)
        .withProvisionedThroughput(new ProvisionedThroughput(1L, 1L))
        .withKeySchema(new KeySchemaElement().withAttributeName("sk").withKeyType(KeyType.HASH),
                new KeySchemaElement().withAttributeName("pk").withKeyType(KeyType.RANGE))
        .withProjection(new Projection().withProjectionType(ProjectionType.ALL));

CreateTableRequest req = this.mapper.generateCreateTableRequest(ItemRecord.class)
        .withProvisionedThroughput(new ProvisionedThroughput(1L, 1L)).withAttributeDefinitions(attrs)
        .withGlobalSecondaryIndexes(reverseIndex);

Есть идеи, что я могу делать не так? Я использую версию 1.11.696 AWS Java SDK.

...