I would like to update a single field in a nested property in DynamoDB. I figured using the UPDATE_SKIP_NULL_ATTRIBUTES
SaveConfiguration
would allow me to do this, but that appears to not be the case.
My DynamoDBTable
:
@Getter
@Setter
@DynamoDBTable(tableName = "users")
public class User {
@DynamoDBHashKey(attributeName = "Id")
@DynamoDBAutoGeneratedKey
private String id;
@DynamoDBAtribute
private String phone;
@DynamoDBAtribute
@DynamoDBTypeConvertedJson(targetType = Name.class)
private Name name;
@Getter
@Setter
@DynamoDBDocument
public static class Name {
@DynamoDBAttribute
private String first;
@DynamoDBAttribute
private String last;
}
}
I have a DynamoDBMapperConfig
initialized like so:
private final DynamoDBMapperConfig config = DynamoDBMapperConfig.builder().withSaveBheavior(DynamoDBMapperConfig.SaveBehavior.UPDATE_SKIP_NULL_ATTRIBUTES).build();
And to save the record, I call the following:
mapper.save(user, config);
where mapper
is a DynamoDBMapper
and user
is a User
shown above.
The issue is that despite using the UPDATE_SKIP_NULL_ATTRIBUTES
configuration, if user.name.last
is null, the DB record's last
field gets updated to null
as well instead of the field being ignored.
This issue does not occur for non-nested fields, such as phone
- if phone
is null
, the record's current value does not get overwritten.
Is there a way to make UPDATE_SKIP_NULL_ATTRIBUTES
apply to nested objects as well? I simply need a way to modify single fields in nested objects.