0
votes

I've checked the DynamoDB documentation, and I can't find anything to confirm or deny whether this is allowed.

Is it valid to use a Document Path for the attributeName of @DynamoDBAttribute, as in this code snippet?

@DynamoDBDocument
public class MyClass {

    @DynamoDBAttribute(attributeName="object.nestedObject.myAttribute")
    private String myAttribute;
    .
    .
    .
    // Getters & Setters, etc
}

Edit: Just to be clear, I am specifically trying to find out whether document paths are valid in the @DynamoDBAttribute Java annotation as a way to directly access a nested value. I know that document paths work in general when specifying a query, but this question is specifically about DynamoDBMapper annotations.

2

2 Answers

0
votes

Yes, the attribute name can have Dot on it. However, in my opinion, it is not recommended to have Dot on attribute name. Usually, the Dot will be used to navigate the tree in Map attribute.

The following are the naming rules for DynamoDB:

All names must be encoded using UTF-8, and are case-sensitive.

Table names and index names must be between 3 and 255 characters long, and can contain only the following characters:

a-z

A-Z

0-9

_ (underscore)

  • (dash)

. (dot)

Attribute names must be between 1 and 255 characters long.

Accessing Map Elements:-

The dereference operator for a map element is . (a dot). Use a dot as a separator between elements in a map:

MyMap.nestedField

MyMap.nestedField.deeplyNestedField

I can create the item with attribute name containing Dot and query the item using FilterExpression successfully.

It works similarly in all language AWS SDKs. As long as data type is defined as String, it would work as expected.

Some JS examples:-

Create Item:-

var table = "Movies";
var year = 2017;
var title = "putitem data test 2";
var dotAttr = "object.nestedObject.myAttribute";        

var params = {
    TableName:table,
    Item:{
        "yearkey": year,
        "title": title,
        "object.nestedObject.myAttribute": "S123"
    },
    ReturnValues : 'NONE'
};

Update:-

It works fine with @DynamoDBAttribute annotation as well.

private String dotAttr;
@DynamoDBAttribute(attributeName = "object.nestedObject.myAttribute")
    public String getDotAttr() {
        return dotAttr;
    }
0
votes

It is not possible to reference a nested path using the attribute name in a @DynamoDBAttribute. I needed to use a POJO type with an added@DynamoDBDocument annotation to represent each level of nesting.