在AWS DynamoDB中没有任何注释的普通POJO

时间:2019-05-04 08:26:16

标签: amazon-dynamodb pojo aws-java-sdk

如何使用无注释的普通POJO类在DynamoDB中创建表?我还必须对它们执行基本的CRUD操作。

`@DynamoDBTable(tableName =“ ProductCatalog”) 公共类CatalogItem {

private Integer id;
private String title;
private String ISBN;
private Set<String> bookAuthors;
private String someProp;

@DynamoDBHashKey(attributeName="Id")  
public Integer getId() { return id; }
public void setId(Integer id) {this.id = id; }

@DynamoDBAttribute(attributeName="Title")  
public String getTitle() {return title; }
public void setTitle(String title) { this.title = title; }

@DynamoDBAttribute(attributeName="ISBN")  
public String getISBN() { return ISBN; }
public void setISBN(String ISBN) { this.ISBN = ISBN; }

@DynamoDBAttribute(attributeName="Authors")
public Set<String> getBookAuthors() { return bookAuthors; }
public void setBookAuthors(Set<String> bookAuthors) { this.bookAuthors = bookAuthors; }
`

在上面的代码中,我需要我的POJO没有任何注释并且仍使用dynamoDB。

1 个答案:

答案 0 :(得分:0)

DynamoDB具有一个中级SDK,可以为您提供帮助。简称为Document Interface。该接口的主要部分是TableItem对象。

现在,要获取一个物品,您可以手动构造一个物品(但您不想这样做),也可以使用Item.fromJson(String)在json blob上进行构造。现在剩下的就是让您使用自己喜欢的序列化程序将java数据模型转换为json。

TLDR ;

Pojo --> json --> Item