将Java类转换为DynamoDb Map< String,AttributeValue> [英] Convert a Java class to DynamoDb Map<String, AttributeValue>

查看:137
本文介绍了将Java类转换为DynamoDb Map< String,AttributeValue>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一些String和int字段的类。我想将此类转换为 Map< String,AttributeValue> 表示形式。我知道DynamoDbMapper在内部执行此操作,但是我们不使用DynamoDbMapper,我想知道是否可以使用现有的库来执行此转换吗?

I have a class which contains some String and int fields. I would like to convert this class to the Map<String, AttributeValue> representation. I know that DynamoDbMapper is doing this internally, but we are not using DynamoDbMapper and I would like to know if there is any existing library that I can use to perform this conversion?

推荐答案

DynamoDB具有一个中级API,您可能会觉得有帮助。其方法之一是 ItemUtils.toAttributeValues(Item) 。此方法使您可以从Item转换为属性值映射。

DynamoDB has a mid-level api that you might find helpful. One of its methods is ItemUtils.toAttributeValues(Item). This method allows you to convert from an Item to an attribute value map.

现在,要获取商品,您可以手动构造一个商品(但您不想这样做),也可以使用 Item.fromJson(String)

Now, to get an Item, you can construct one manually (but you don’t want to) or you can construct on from a json blob using Item.fromJson(String).

现在剩下的就是让您使用自己喜欢的序列化程序从您的Java数据模型转换为json。我提到的方法可以无缝处理其余的转换。

Now all that remains is for you to use your favorite serializer to convert from your java data model to json. The methods I’ve mentioned seamlessly handle the rest of the conversion.

TLDR ;

Pojo --> json --> Item --> Map<String, AttributeValue>

这篇关于将Java类转换为DynamoDb Map&lt; String,AttributeValue&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆