Is there a way to update a nested attribute in DynamoDB using DynamoDB Mapper

502 Views Asked by At

I have a DynamoDB Schema with nested attributes. Hence lets say below is my mapper structure.

public class Test
{
@DynamoDBHashKey private String testPk;
@DynamoDBRangeKey private String testSk;
@DynamoDBAttribute private String name;
@DynamoDBAttribute private MyClass myClass;
}

@DynamoDBDocument
public class MyClass{
@DynamoDBAttribute private String myName;
@DynamoDBAttribute private String mySubject;
}

Now this would lead to a schema like:

{
"testPk":<value>,
"testSk":<value,
"name":<value>,
"myClass":{
      "myName":<value>,
      "mySubject":<value>
   }
}

I am using a Dynamo DB Mapper to update this object. The dynamo DB Mapper config is as follows:

 DynamoDBMapperConfig.builder() .withSaveBehavior(DynamoDBMapperConfig.SaveBehavior.UPDATE_SKIP_NULL_ATTRIBUTES) .withConsistentReads(DynamoDBMapperConfig.ConsistentReads.EVENTUAL) .build();

This is done so that fields that are null/not updated are ignored by the save operation.

However as per my observation, this configuration is only working for the primitive Data Types in the "Test" class and not for the custom DynamoDBDocument(MyClass) defined in the mapper(Test.java). Whenever I am trying to update the MyClass object, if I try to change only "myName", "mySubject" gets set to null which overrides its older value which means "update_skip_null_attributes" is not working on the DynamoDBDocument.

How can I change this update behavior on the nested json.?

Any help will be appreciated.

0

There are 0 best solutions below