0

I understand there may be cleaner ways to store these data, I'm skipping that part for the sake of my sanity in dealing with legacy code.

I want to store an object that looks like this in DynamoDB:

@DynamoDBTable(tableName="TableName")
public class MyItem {

    // DynamoDB Attributes
    private String hashKey;
    private String someAttribute;
    private Map<String, Config> configs;

    @DynamoDBHashKey(attributeName = "hash_key")
    public String getHashKey() {
        return this.hashKey;
    }
    public void setHashKey(String hashKey) {
        this.hashKey = hashKey;
    }

    @DynamoDBAttribute(attributeName = "some_attribute")
    public String getSomeAttribute() {
        return this.someAttribute;
    }
    public void setSomeAttribute(String someAttribute ) {
        this.someAttribute = someAttribute;
    }

    @DynamoDBAttribute(attributeName = "configs")
    public Map<String, Config> getConfigs() {
        return this.configs;
    }
    public void setConfigs(Map<String, Config> configs) 
    {
        this.configs = configs;
    }
}

With a supplemental class

@DynamoDBDocument
public class Config {
    private String field;

    @DynamoDBAttribute(attributeName="field")
    public String getField() {
        return field;
    }
    public void setField(String field) {
        this.field = field;
    }
}
  1. Will this work as written?
  2. What would the resulting entry look like in DynamoDB for the following JSON:
{
    "hash_key":"123",
    "some_attribute":"attribute_value",
    "a_config_key" : {
        "field":"field_value"
    }
}
  • thank you for your post. To help your better a minimized code example would be better. I also ask myself why don't you execute the code in a simple stand-alone test-application? – finder2 Aug 18 '21 at 07:16

1 Answers1

0

I would recommend you to implement your own converter using @DynamoDbConvertedBy (the official dynamodb-enhanced client).

Hopefully, this sample is helpful: https://stackoverflow.com/a/70602166/12869305

Alex A
  • 51
  • 1
  • 5
  • Add this as a comment on the post, this doesn't look like an answer to the question. – Deepak Kumar Jan 11 '22 at 05:31
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/30749950) – Deepak Kumar Jan 11 '22 at 05:32