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

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

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

クライアントの作成

ユースケース 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 Enhanced Client オペレーションをカスタマイズする セクションには、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 メソッドについて説明する DynamoDB デベロッパーガイドの セクションは、完全な例を示しています。 V1 query

  1. GSI の場合) と @DynamoDbSecondaryPartitionKey (GSI または LSI @DynamoDbSecondarySortKey の場合) を使用して POJO クラスの属性に注釈を付けます。例えば、 などです

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

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

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

Table operations

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

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

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

表示されていない場合でも、ほとんどの V2 オペレーションは流暢なコンシューマーパターンで呼び出すことができることに注意してください。例えば、 などです

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)
Table operations
ユースケース V1 V2

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

DynamoDB オペレーション: PutItemUpdateItem

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

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

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)

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

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

DynamoDB オペレーション: Query

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

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

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

DynamoDB オペレーション: Scan

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

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

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

DynamoDB オペレーション: Scan

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

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

バッチ内の複数のテーブルから複数の項目を読み取る

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 オペレーション: QuerySelect.COUNT

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 オペレーション:ScanSelect.COUNT

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 での eager ロードと同等のものを実装できます。

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

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

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

UPDATE

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

CLOBBER or PUT: v 2 の対応するアクションが を呼び出しています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()、can()
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 はすべての一般的なタイプのデフォルトコンバータのセットを提供します。タイプコンバータは、プロバイダーレベル全体と 1 つの属性の両方で変更できます。使用可能なコンバータのリストは、AttributeConverter API リファレンスで確認できます。

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

V1 では、 を使用して getter メソッドに注釈を付けて@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 の完全な例が含まれています。