3

How do I use a plain POJO class without any annotations to create tables in DynamoDB? I also have to perform basic CRUD operations on them.

`@DynamoDBTable(tableName="ProductCatalog") public class 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; }
`

In the above code, I need my POJO to be without any annotation and still use dynamoDB.

Viman
  • 41
  • 4
  • Hey, did the answer end up working for you? If it did, you should accept it so that other SO users know that it solves the problem. If you had to tweak a few things or if you used a different solution, leave a comment or add your own answer to share that knowledge with others. – Matthew Pope Jul 20 '19 at 05:15

1 Answers1

0

DynamoDB has a mid-level SDK that can help you out. It’s referred to as the Document Interface. The main parts of this interface are the Table and Item objects.

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). Now all that remains is for you to use your favorite serializer to convert from your java data model to json.

TLDR;

Pojo --> json --> Item
Matthew Pope
  • 7,212
  • 1
  • 28
  • 49