Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Item to Map<String, AttributeValue> for DynamoDB in Java

Is there any Java API for DynamoDB to convert from Item to Map<String, AttributeValue> without implementing it on my own?

EDIT

item.asMap() will return Map<String, Object>, not Map<String, AttributeValue>. Just wondering is there any direct API for this?

like image 813
Kaidul Avatar asked Jan 28 '23 00:01

Kaidul


2 Answers

Yeah, but I've managed to find it:

// Item item
InternalUtils.toAttributeValues(item)

However, above API is deprecated in newer DynamoDB library which basically delegates the call to ItemUtils which is not deprecated fortunately. So I ended up using this:

ItemUtils.toAttributeValues(item)

Hope this will help others in future!

like image 162
Kaidul Avatar answered May 01 '23 08:05

Kaidul


You can use the method asMap:

Returns all attributes of the current item as a map.


Updated answer:

To get a Map<String, AttributeValue> you can use ItemUtils.toAttributeValue:

Converts an Item into the low-level representation; or null if the input is null.

as follow

Map<String, AttributeValue> map = ItemUtils.toAttributeValue(item);
like image 45
Davide Lorenzo MARINO Avatar answered May 01 '23 08:05

Davide Lorenzo MARINO