I am trying to do a scan of a DynamoDB table and then display user selected fields in a table. The problem is how can I do this if data is returned as AttributeValues, since not all values will be a string, and I have no idea what type each value is before hand.
The code I have:
ScanRequest request =
ScanRequest
.builder()
.tableName(tableName))
.build();
ScanIterable response = client.scanPaginator(request);
List<Map<String, AttributeValue>> data = new ArrayList<>();
for (ScanResponse page : response) {
for (Map<String, AttributeValue> item : page.items()) {
data.add(item);
}
}
then to get the values:
for (Map<String, AttributeValue> map : items) {
for (Map.Entry<String, AttributeValue> entry : map.entrySet()) {
//get the entry.getValue() and append it to a string
}
}
If I use:
entry.getValue().toString()
I will get a string containing the attribute value type and value e.g 'N': '127' If I use:
entry.getValue().s()
I will get null values when the type is not 'S'