1

Amazon AWSからDynamoDBを学習しようとしていて、データを正常に取得できましたが、使用可能な形式に変換するのに苦労しています。Amazon AWS DynamoDBからオブジェクトのArrayListへのリストの変換

私の目標は、属性、ゲッタ、セッタを持つValueObjectクラスであるMy Dataデータ型のArrayListに結果を変換することです。

ありがとうございます!

Map<String,String> expressionAttributesNames = new HashMap<>(); 
expressionAttributesNames.put("#network_asset_code","network_asset_code"); 
expressionAttributesNames.put("#temperature","temperature"); 

Map<String,AttributeValue> expressionAttributeValues = new HashMap<>(); 
expressionAttributeValues.put(":network_asset_codeValue", new AttributeValue().withS("17AB05")); 
expressionAttributeValues.put(":temperature", new AttributeValue().withN("21")); 

ScanRequest scanRequest = new ScanRequest() 
    .withTableName("things") 
    .withFilterExpression("#network_asset_code = :network_asset_codeValue and #temperature = :temperature") 
    .withExpressionAttributeNames(expressionAttributesNames) 
    .withExpressionAttributeValues(expressionAttributeValues); 


ScanResult scanResult = client.scan(scanRequest); 

List<Map<String,AttributeValue>> attributeValues = scanResult.getItems(); 
ArrayList<Data> dataArray = new ArrayList<>(); 

for (Map map: attributeValues) { 
    Data d = map.values(); 
    dataArray.add(d); 
} 

答えて

0

しばらくして、私はそれが権利を取得できます:あなたは自動的annotationsを使用してJavaオブジェクト(POJO)にDynamoDBの項目を変換するDynamoDBMapperを使用することができます

for (Map map: attributeValues) { 

      AttributeValue attr = (AttributeValue) map.get("network_asset_code"); 

      Data d = new Data(); 
      d.network_asset_code = attr.getS(); 

      dataArray.add(d); 
     } 
1

関連する問題