SDK for Java のバージョン 1 とバージョン 2 での DynamoDB マッピング API の変更 - AWS SDK for Java 2.x

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

SDK for Java のバージョン 1 とバージョン 2 での DynamoDB マッピング API の変更

クライアントの作成

ユースケース V1 V2

通常のインスタンス化

AmazonDynamoDB standardClient = AmazonDynamoDBClientBuilder.standard() .withCredentials(credentialsProvider) .withRegion(Regions.US_EAST_1) .build(); DynamoDBMapper mapper = new DynamoDBMapper(standardClient);
DynamoDbClient standardClient = DynamoDbClient.builder() .credentialsProvider(ProfileCredentialsProvider.create()) .region(Region.US_EAST_1) .build(); DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder() .dynamoDbClient(standardClient) .build();

最小限のインスタンス化

AmazonDynamoDB standardClient = AmazonDynamoDBClientBuilder.standard(); DynamoDBMapper mapper = new DynamoDBMapper(standardClient);
DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.create();

属性トランスフォーマーを使用*

DynamoDBMapper mapper = new DynamoDBMapper(standardClient, attributeTransformerInstance);
DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder() .dynamoDbClient(standardClient) .extensions(extensionAInstance, extensionBInstance) .build();

*V2 の拡張機能は、V1 の属性トランスフォーマーにほぼ対応しています。拡張機能を使用して DynamoDB 拡張クライアントオペレーションをカスタマイズする セクションには、V2 の拡張機能に関する詳細情報が記載されています。

DynamoDB テーブル/インデックスへのマッピングを確立する

V1 では、Bean 注釈を使用して DynamoDB テーブル名を指定します。V2 では、ファクトリメソッドである table() がリモート DynamoDB テーブルを表す DynamoDbTable のインスタンスを生成します。table() メソッドの最初のパラメータは、DynamoDB テーブル名です。

ユースケース V1 V2

Java POJO クラスを DynamoDB テーブルにマッピングする

@DynamoDBTable(tableName ="Customer") public class Customer { ... }
DynamoDbTable<Customer> customerTable = enhancedClient.table("Customer", TableSchema.fromBean(Customer.class));

DynamoDB セカンダリインデックスへのマッピング

  1. インデックスを表す POJO クラスを定義します。

    • インデックスを持つテーブルの名前を指定する @DynamoDBTable でクラスに注釈を付けます。

    • @DynamoDBIndexHashKey およびオプションで @DynamoDBIndexRangeKey を使用して、プロパティに注釈を付けます。

  2. クエリ式を作成します。

  3. インデックスを表す POJO クラスへの参照を使用してクエリを実行します。例

    mapper.query(IdEmailIndex.class, queryExpression)

    ここで、IdEmailIndex はインデックスのマッピングクラスです。

V1 の query メソッドについて説明する DynamoDB デベロッパーガイドのセクションでは、完全な例を示しています。

  1. @DynamoDbSecondaryPartitionKey (GSI の場合) および @DynamoDbSecondarySortKey (GSI または LSI の場合) を使用して POJO クラスの属性に注釈を付けます。例、

    @DynamoDbSecondarySortKey(indexNames = "IdEmailIndex") public String getEmail() { return this.email; }
  2. インデックスへの参照を取得します。例、

    DynamoDbIndex<Customer> customerIndex = customerTable.index("IdEmailIndex");
  3. インデックスをクエリします。

詳細については、このガイドの「セカンダリインデックスを使用する」セクションを参照してください。

テーブルの操作

このセクションでは、ほとんどの標準的なユースケースにおいて V1 と V2 で異なるオペレーション API について説明します。

V2 では、単一のテーブルを含むすべてのオペレーションが、拡張クライアントではなく DynamoDbTable インスタンスで呼び出されます。拡張クライアントには、複数のテーブルをターゲットにできるメソッドが含まれています。

以下の「テーブルオペレーション」という表では、POJO インスタンスは item または customer1 などの特定のタイプとして記載されています。V2 の例の場合、table という名前のインスタンスは、DynamoDbTable インスタンスへの参照を返す enhancedClient.table() を以前に呼び出した結果です。

ほとんどの V2 オペレーションは、表示されていない場合で fluent コンシューマーパターンで呼び出すことができます。例、

Customer customer = table.getItem(r → r.key(key)); or Customer customer = table.getItem(r → r.key(k -> k.partitionValue("id").sortValue("email")))

V1 オペレーションの場合、テーブルオペレーション (以下) には一般的に使用される形式の一部のみが含まれており、すべてのオーバーロードされた形式が含まれているわけではありません。たとえば、 load() メソッドには次のオーバーロードがあります。

mapper.load(Customer.class, hashKey) mapper.load(Customer.class, hashKey, rangeKey) mapper.load(Customer.class, hashKey, config) mapper.load(Customer.class, hashKey, rangeKey, config) mapper.load(item) mapper.load(item, config)

テーブルオペレーション (以下) は、一般的に使用される形式を示しています。

mapper.load(item) mapper.load(item, config)
テーブルの操作
ユースケース V1 V2

Java POJO を DynamoDB テーブルに書き込む

DynamoDB オペレーション:PutItemUpdateItem

mapper.save(item) mapper.save(item, config) mapper.save(item, saveExpression, config)

V1 では、DynamoDBMapperConfig.SaveBehavior および注釈によって、呼び出される低レベルの DynamoDB メソッドが決まります。一般的に、SaveBehavior.CLOBBERSaveBehavior.PUT を使用する場合を除いて UpdateItem が呼び出されます。自動生成されたキーは特殊なユースケースであり、PutItemUpdateItem の両方が使用されることもあります。

table.putItem(putItemRequest) table.putItem(item) table.putItemWithResponse(item) //Returns metadata. updateItem(updateItemRequest) table.updateItem(item) table.updateItemWithResponse(item) //Returns metadata.

DynamoDB テーブルから Java POJO に項目を読み込む

DynamoDB オペレーション: GetItem

mapper.load(item) mapper.load(item, config)
table.getItem(getItemRequest) table.getItem(item) table.getItem(key) table.getItemWithResponse(key) //Returns POJO with metadata.

DynamoDB テーブルから項目を削除します。

DynamoDB オペレーション: DeleteItem

mapper.delete(item, deleteExpression, config)
table.deleteItem(deleteItemRequest) table.deleteItem(item) table.deleteItem(key)

DynamoDB テーブルまたはセカンダリインデックスをクエリし、ページ分割されたリストを返します。

DynamoDB オペレーション: Query

mapper.query(Customer.class, queryExpression) mapper.query(Customer.class, queryExpression, mapperConfig)
table.query(queryRequest) table.query(queryConditional)

同期レスポンスには返された PageIterable.stream() (遅延読み込み) を、非同期レスポンスには PagePublisher.subscribe() を使用します。

DynamoDB テーブルまたはセカンダリインデックスをクエリしてリストを返します。

DynamoDB オペレーション: Query

mapper.queryPage(Customer.class, queryExpression) mapper.queryPage(Customer.class, queryExpression, mapperConfig)
table.query(queryRequest) table.query(queryConditional)

同期レスポンスには返された PageIterable.items() (遅延読み込み) を、非同期レスポンスには PagePublisher.items.subscribe() を使用します。

DynamoDB テーブルまたはセカンダリインデックスをスキャンしてページ分割されたリストを返します。

DynamoDB オペレーション: Scan

mapper.scan(Customer.class, scanExpression) mapper.scan(Customer.class, scanExpression, mapperConfig)
table.scan() table.scan(scanRequest)

同期レスポンスには返された PageIterable.stream() (遅延読み込み) を、非同期レスポンスには PagePublisher.subscribe() を使用します。

DynamoDB テーブルまたはセカンダリインデックスをスキャンしてリストを返します。

DynamoDB オペレーション: Scan

mapper.scanPage(Customer.class, scanExpression) mapper.scanPage(Customer.class, scanExpression, mapperConfig)
table.scan() table.scan(scanRequest)

同期レスポンスには返された PageIterable.items() (遅延読み込み) を、非同期レスポンスには PagePublisher.items.subscribe() を使用します。

複数のテーブルから複数の項目をバッチで読み取ります。

DynamoDB オペレーション: BatchGetItem

mapper.batchLoad(Arrays.asList(customer1, customer2, book1)) mapper.batchLoad(itemsToGet) // itemsToGet: Map<Class<?>, List<KeyPair>>
enhancedClient.batchGetItem(batchGetItemRequest) enhancedClient.batchGetItem(r -> r.readBatches( ReadBatch.builder(Record1.class) .mappedTableResource(mappedTable1) .addGetItem(i -> i.key(k -> k.partitionValue(0))) .build(), ReadBatch.builder(Record2.class) .mappedTableResource(mappedTable2) .addGetItem(i -> i.key(k -> k.partitionValue(0))) .build())) // Iterate over pages with lazy loading or over all items from the same table.

複数のテーブルに複数の項目をバッチで書き込みます。

DynamoDB オペレーション: BatchWriteItem

mapper.batchSave(Arrays.asList(customer1, customer2, book1))
enhancedClient.batchWriteItem(batchWriteItemRequest) enhancedClient.batchWriteItem(r -> r.writeBatches( WriteBatch.builder(Record1.class) .mappedTableResource(mappedTable1) .addPutItem(item1) .build(), WriteBatch.builder(Record2.class) .mappedTableResource(mappedTable2) .addPutItem(item2) .build()))

複数のテーブルから複数の項目をバッチで削除します。

DynamoDB オペレーション: BatchWriteItem

mapper.batchDelete(Arrays.asList(customer1, customer2, book1))
enhancedClient.batchWriteItem(r -> r.writeBatches( WriteBatch.builder(Record1.class) .mappedTableResource(mappedTable1) .addDeleteItem(item1key) .build(), WriteBatch.builder(Record2.class) .mappedTableResource(mappedTable2) .addDeleteItem(item2key) .build()))

複数の項目をバッチで書き込み/削除します。

DynamoDB オペレーション: BatchWriteItem

mapper.batchWrite(Arrays.asList(customer1, book1), Arrays.asList(customer2))
enhancedClient.batchWriteItem(r -> r.writeBatches( WriteBatch.builder(Record1.class) .mappedTableResource(mappedTable1) .addPutItem(item1) .build(), WriteBatch.builder(Record2.class) .mappedTableResource(mappedTable2) .addDeleteItem(item2key) .build()))

トランザクション書き込みを実行します。

DynamoDB オペレーション: TransactWriteItems

mapper.transactionWrite(transactionWriteRequest)
enhancedClient.transactWriteItems(transasctWriteItemsRequest)

トランザクション読み取りを実行します。

DynamoDB オペレーション: TransactGetItems

mapper.transactionLoad(transactionLoadRequest)
enhancedClient.transactGetItems(transactGetItemsRequest)

クエリの一致する項目の数を取得します。

DynamoDB オペレーション: Select.COUNT によるQuery

mapper.count(Customer.class, queryExpression)
// Get the count from query results. PageIterable<Customer> pageIterable = customerTable.query(QueryEnhancedRequest.builder() .queryConditional(queryConditional) .select(Select.COUNT) .build()); Iterator<Page<Customer>> iterator = pageIterable.iterator(); Page<Customer> page = iterator.next(); int count = page.count(); // For a more concise approach, you can chain the method calls: int count = customerTable.query(QueryEnhancedRequest.builder() .queryConditional(queryConditional) .select(Select.COUNT) .build()) .iterator().next().count();

スキャンの一致する項目の数を取得します。

DynamoDB オペレーション: Select.COUNT による Scan

mapper.count(Customer.class, scanExpression)
// Get the count from scan results. PageIterable<Customer> pageIterable = customerTable.scan(ScanEnhancedRequest.builder() .filterExpression(filterExpression) .select(Select.COUNT) .build()); Iterator<Page<Customer>> iterator = pageIterable.iterator(); Page<Customer> page = iterator.next(); int count = page.count(); // For a more concise approach, you can chain the method calls: int count = customerTable.scan(ScanEnhancedRequest.builder() .filterExpression(filterExpression) .select(Select.COUNT) .build()) .iterator().next().count();

POJO クラスに対応するテーブルを DynamoDB に作成します。

DynamoDB オペレーション: CreateTable

mapper.generateCreateTableRequest(Customer.class)

前のステートメントは、低レベルのテーブル作成リクエストを生成します。ユーザーは DynamoDB クライアントで createTable を呼び出す必要があります。

table.createTable(createTableRequest) table.createTable(r -> r.provisionedThroughput(defaultThroughput()) .globalSecondaryIndices( EnhancedGlobalSecondaryIndex.builder() .indexName("gsi_1") .projection(p -> p.projectionType(ProjectionType.ALL)) .provisionedThroughput(defaultThroughput()) .build()));

DynamoDB で並列スキャンを実行します。

DynamoDB オペレーション: SegmentTotalSegments パラメータを使用した Scan

mapper.parallelScan(Customer.class, scanExpression, numTotalSegments)

ユーザーはワーカースレッドを処理し、セグメントごとに scan を呼び出す必要があります。

table.scan(r -> r.segment(0).totalSegments(5))

Amazon S3 と DynamoDB を統合してインテリジェントな S3 リンクを保存します。

mapper.createS3Link(bucket, key) mapper.getS3ClientCache()

Amazon S3 と DynamoDB が結合されるため、サポートされていません。

クラスとプロパティをマッピングする

V1 と V2 の両方で、Bean 形式の注釈を使用してクラスをテーブルにマッピングします。V2 には、変更不可能なクラスの使用など、特定のユースケースのスキーマを定義する他の方法もあります。

Bean 注釈

次の表は、V1 および V2 で使用される、特定のユースケースにおける同等の Bean 注釈を示しています。Customer クラスシナリオは、パラメータを説明するために使用されます。

V2 の注釈、クラス、列挙はキャメルケース規則に従い、「DynamoDB」ではなく「DynamoDb」を使用します。

ユースケース V1 V2
クラスをテーブルにマップする
@DynamoDBTable (tableName ="CustomerTable")
@DynamoDbBean @DynamoDbBean(converterProviders = {...})
テーブル名は、DynamoDbEnhancedClient#table() メソッドを呼び出すときに定義されます。
クラスメンバーをテーブル属性として指定する
@DynamoDBAttribute(attributeName = "customerName")
@DynamoDbAttribute("customerName")
クラスメンバーをハッシュ/パーティションキーとして指定する
@DynamoDBHashKey
@DynamoDbPartitionKey
クラスメンバーを範囲/ソートキーとして指定する
@DynamoDBRangeKey
@DynamoDbSortKey
クラスメンバーをセカンダリインデックスのハッシュ/パーティションキーとして指定する
@DynamoDBIndexHashKey
@DynamoDbSecondaryPartitionKey
クラスメンバーをセカンダリインデックスの範囲/ソートキーとして指定する
@DynamoDBIndexRangeKey
@DynamoDbSecondarySortKey
テーブルにマッピングするときにこのクラスメンバーを無視する
@DynamoDBIgnore
@DynamoDbIgnore
クラスメンバーを自動生成された UUID キー属性として指定する
@DynamoDBAutoGeneratedKey
@DynamoDbAutoGeneratedUuid

これを提供する拡張機能はデフォルトではロードされません。拡張機能をクライアントビルダーに追加する必要があります。

クラスメンバーを自動生成されたタイムスタンプ属性として指定する
@DynamoDBAutoGeneratedTimestamp
@DynamoDbAutoGeneratedTimestampAttribute

これを提供する拡張機能はデフォルトではロードされません。拡張機能をクライアントビルダーに追加する必要があります。

クラスメンバーを自動で増分されるバージョン属性として指定する
@DynamoDBVersionAttribute
@DynamoDbVersionAttribute

これを提供する拡張機能は自動的にロードされます。

クラスメンバーをカスタム変換を必要とするものとして指定する
@DynamoDBTypeConverted
@DynamoDbConvertedBy
クラスメンバーを別の属性タイプとして保存するように指定する
@DynamoDBTyped(<DynamoDBAttributeType>)

AttributeConverter 実装を使用します。V2 には、一般的な Java タイプ用の多くの組み込みコンバーターが用意されています。独自のカスタム AttributeConverter または AttributeConverterProvider を実装することもできます。本ガイドの「属性変換を制御する」を参照してください。

DynamoDB ドキュメント (JSON 形式のドキュメント) またはサブドキュメントにシリアル化できるクラスを指定する
@DynamoDBDocument
拡張ドキュメント API を使用します。以下のリソースを参照してください。

V2 の追加注釈

ユースケース V1 V2
Java 値が null の場合、クラスメンバーを NULL 属性として保存しないように指定する 該当なし
@DynamoDbIgnoreNulls
すべての属性が null の場合、クラスメンバーを空のオブジェクトとなるように指定する 該当なし
@DynamoDbPreserveEmptyObject
クラスメンバーの特別な更新アクションを指定する 該当なし
@DynamoDbUpdateBehavior
変更不可能なクラスを指定する 該当なし
@DynamoDbImmutable
クラスメンバーを自動で増分されるカウンター属性として指定する 該当なし
@DynamoDbAtomicCounter

この機能を提供する拡張機能は自動的にロードされます。

設定

V1 では、通常、DynamoDBMapperConfig のインスタンスを使用して特定の動作を制御します。設定オブジェクトは、マッパーの作成時またはリクエスト時に指定できます。V2 では、設定は オペレーションのリクエストオブジェクトに固有です。

ユースケース V1 V1 のデフォルト V2
DynamoDBMapperConfig.builder()
バッチロード/書き込みの再試行戦略
.withBatchLoadRetryStrategy(loadRetryStrategy)
.withBatchWriteRetryStrategy(writeRetryStrategy)
失敗した項目を再試行する 基盤となる DynamoDBClient で再試行戦略を設定します。本ガイドの「AWS SDK for Java 2.x で再試行動作を設定する」を参照してください。
整合性のある読み込み
.withConsistentReads(CONSISTENT)
EVENTUAL デフォルトでは、読み取りオペレーションの整合性のある読み取りは false です。リクエストオブジェクトで、.consistentRead(true) で上書きします。
マーシャラー/アンマーシャラーのセットによる変換スキーマ
.withConversionSchema(conversionSchema)

静的実装は、古いバージョンとの下位互換性を提供します。

V2_COMPATIBLE 該当なし。これは、初期の DynamoDB(V1)がデータ型を保存していた方法を指すレガシー機能であり、この動作は拡張クライアントでは保持されません。DynamoDB V1 の動作の一例は、ブール値ではなく数値としてブール値を格納することです。
テーブル名
.withObjectTableNameResolver() .withTableNameOverride() .withTableNameResolver()

静的実装は、古いバージョンとの下位互換性を提供します。

注釈を使用する、またはクラスから推測する

テーブル名は、DynamoDbEnhancedClient#table() メソッドを呼び出すときに定義されます。

ページ分割ロード戦略
.withPaginationLoadingStrategy(strategy)

オプション: LAZY_LOADINGEAGER_LOADING、または ITERATION_ONLY

LAZY_LOADING
  • デフォルトはイテレーションのみです。他の V1 オプションはサポートされていません。

  • 以下を使用して、V2 で積極的なロードと同等の機能を実装できます。

    List<Customer> allItems = customerTable.scan().items().stream().collect(Collectors.toList());
  • 遅延ロードでは、アクセスされた項目に独自のキャッシュロジックを実装する必要があります。

リクエストメトリクスの収集
.withRequestMetricCollector(collector)
null 標準 DynamoDB クライアントを構築するときは、metricPublisher()ClientOverrideConfiguration を使用します。
保存動作
.withSaveBehavior(SaveBehavior.CLOBBER)

オプションは UPDATECLOBBERPUTAPPEND_SET、または UPDATE_SKIP_NULL_ATTRIBUTES です。

UPDATE

V2 では、putItem() または updateItem() を明示的に呼び出します。

CLOBBER or PUT: V2 の対応するアクションが putItem() を呼び出します。特定の CLOBBER 設定はありません。

UPDATE に対応しています。updateItem()

UPDATE_SKIP_NULL_ATTRIBUTES に対応しています。updateItem()リクエスト設定 ignoreNulls と注釈/タグ DynamoDbUpdateBehavior を使用して更新動作を制御します。

APPEND_SETサポート外:

型コンバータファクトリ
.withTypeConverterFactory(typeConverterFactory)
標準型コンバータ

次を使用して Bean に設定する

@DynamoDbBean(converterProviders = {ConverterProvider.class, DefaultAttributeConverterProvider.class})

オペレーションごとの設定

V1 では、query() などの一部のオペレーションは、オペレーションに送信された「式」オブジェクトを使用して高度に設定できます。例:

DynamoDBQueryExpression<Customer> emailBwQueryExpr = new DynamoDBQueryExpression<Customer>() .withRangeKeyCondition("Email", new Condition() .withComparisonOperator(ComparisonOperator.BEGINS_WITH) .withAttributeValueList( new AttributeValue().withS("my"))); mapper.query(Customer.class, emailBwQueryExpr);

V2 では、設定オブジェクトを使用する代わりに、ビルダーを使用してリクエストオブジェクトにパラメータを設定します。例:

QueryEnhancedRequest emailBw = QueryEnhancedRequest.builder() .queryConditional(QueryConditional .sortBeginsWith(kb -> kb .sortValue("my"))).build(); customerTable.query(emailBw);

条件式

V2 では、条件式とフィルタリング式は、条件と名前およびフィルターのマッピングをカプセル化する Expression オブジェクトを使用して表現されます。

ユースケース オペレーション V1 V2
予想される属性条件 save()、delete()、Query()、Scan()
new DynamoDBSaveExpression() .withExpected(Collections.singletonMap( "otherAttribute", new ExpectedAttributeValue(false))) .withConditionalOperator(ConditionalOperator.AND);
非推奨。代わりに ConditionExpression を使用してください。
条件式 delete()
deleteExpression.setConditionExpression("zipcode = :zipcode") deleteExpression.setExpressionAttributeValues(...)
Expression conditionExpression = Expression.builder() .expression("#key = :value OR #key1 = :value1") .putExpressionName("#key", "attribute") .putExpressionName("#key1", "attribute3") .putExpressionValue(":value", AttributeValues.stringValue("wrong")) .putExpressionValue(":value1", AttributeValues.stringValue("three")) .build(); DeleteItemEnhancedRequest request = DeleteItemEnhancedRequest.builder() .conditionExpression(conditionExpression).build();
フィルター式 query()、scan()
scanExpression .withFilterExpression("#statename = :state") .withExpressionAttributeValues(attributeValueMapBuilder.build()) .withExpressionAttributeNames(attributeNameMapBuilder.build())
Map<String, AttributeValue> values = singletonMap(":key", stringValue("value")); Expression filterExpression = Expression.builder() .expression("name = :key") .expressionValues(values) .build(); QueryEnhancedRequest request = QueryEnhancedRequest.builder() .filterExpression(filterExpression).build();
クエリの条件式 query()
queryExpression.withKeyConditionExpression()
QueryConditional keyEqual = QueryConditional.keyEqualTo(b -> b .partitionValue("movie01")); QueryEnhancedRequest tableQuery = QueryEnhancedRequest.builder() .queryConditional(keyEqual) .build();

型変換

デフォルトコンバータ

V2 では、SDK はすべての一般的なタイプに向けてデフォルトコンバータのセットを提供します。タイプコンバータは、全体的なプロバイダーレベルと、単一の属性に対しての両方で変更できます。使用可能なコンバータのリストは、AttributeConverter API リファレンスで確認できます。

属性のカスタムコンバータを設定する

V1 では、@DynamoDBTypeConverted を使用してゲッターメソッドに注釈を付けて、Java 属性型と DynamoDB 属性型を変換するクラスを指定できます。たとえば、Java Currency 型と DynamoDB 文字列を変換する CurrencyFormatConverter は、次のスニペットに示すように適用できます。

@DynamoDBTypeConverted(converter = CurrencyFormatConverter.class) public Currency getCurrency() { return currency; }

での前のスニペットに相当する V2 でのスニペットを以下に示します。

@DynamoDbConvertedBy(CurrencyFormatConverter.class) public Currency getCurrency() { return currency; }
注記

V1 では、属性自体、タイプ、またはユーザー定義の注釈に注釈を適用できます。V2 では、ゲッターにのみ注釈を適用できます。

タイプコンバータファクトリまたはプロバイダーを追加する

V1 では、独自のタイプコンバータのセットを提供するか、設定にタイプコンバータファクトリを追加することで、任意のタイプを上書きできます。タイプコンバータファクトリは DynamoDBTypeConverterFactory を拡張し、デフォルトセットへの参照を取得してそれを拡張することによって上書きが行われます。以下のスニペットは、その方法を示しています。

DynamoDBTypeConverterFactory typeConverterFactory = DynamoDBTypeConverterFactory.standard().override() .with(String.class, CustomBoolean.class, new DynamoDBTypeConverter<String, CustomBoolean>() { @Override public String convert(CustomBoolean bool) { return String.valueOf(bool.getValue()); } @Override public CustomBoolean unconvert(String string) { return new CustomBoolean(Boolean.valueOf(string)); }}).build(); DynamoDBMapperConfig config = DynamoDBMapperConfig.builder() .withTypeConverterFactory(typeConverterFactory) .build(); DynamoDBMapper mapperWithTypeConverterFactory = new DynamoDBMapper(dynamo, config);

V2 は、@DynamoDbBean 注釈を通じて同様の機能を提供します。単一の AttributeConverterProvider または順序付けられた AttributeConverterProvider のチェーンを提供することができます。独自の属性コンバータープロバイダーチェーンを指定すると、デフォルトのコンバータープロバイダーが上書きされ、その属性コンバータを使用するにはチェーンに含める必要があることに注意してください。

@DynamoDbBean(converterProviders = { ConverterProvider1.class, ConverterProvider2.class, DefaultAttributeConverterProvider.class}) public class Customer { ... }

本ガイドの属性変換に関するセクションには、V2 の完全な例が含まれています。