简体   繁体   中英

AWS Java SDK DynamoDB, how to get attribute values from ExecuteStatementRequest response?

I'm using Java AWS SDK to query a DynamoDB table using ExecuteStatementRequest , but I'm don't know how to fetch the returned attribute values from the response.

Given I have the following query:

var response2 = client.executeStatement(ExecuteStatementRequest.builder()
    .statement("""
        UPDATE "my-table"
        SET thresholdValue= thresholdValue + 12.5
        WHERE assignmentId='item1#123#item2#456#item3#789'
        RETURNING ALL NEW *
    """)
    .build());
System.out.println(response2.toString());
System.out.println(response2.getValueForField("Items", Collections.class)); // Doesn't cast to

This query executes fine and returns as part of the response attributes, however I can't find a way to get these values out of the response object using Java.

How can I do that?

I have found how to do that, however I'm not sure it this is the indicated way as the documentation doesn't provide any examples.

List items = response2.getValueForField("Items", List.class).get();
for (Object item : items) {
    var values = (Map<String, AttributeValue>) item;
    System.out.println(values.get("assignmentId").s());
    System.out.println(values.get("thresholdValue").n());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM