Open
Description
Describe the bug
When executing DynamoDbTable.updateItem
for a few fields, the execution clear the existing data and only sets new field values from input object.
My understanding, for an existing record, when a Java object populated with primary key and fields to be changed, this operation should affect only the fields to be changed for the primary key record.
Curious to know, how is this updateItem
supposed to work?
Expected Behavior
- The
updateItem
should only change the fields which are present in the input - This begs a question what should happen to the default values which are assigned as
null
. There is a field level annotation for ignoring null (I tried, it didn't work for me either). Also, need a class level annotation for ignoring all null fields.
Current Behavior
Overwriting existing contents of a record for updateItem
operation.
I am using spring-cloud-aws-starter-dynamodb
using DynamoDbTemplate
AWS Spring DynamoDb, however, it fails when using below code snippet
/*
Existing record:
Car(vin=1234567890, color=white, year=2020, model=Ford Mustang)
*/
final Car car = Car
.builder()
.vin("1234567890")
.color("black") // existing record has white color
.build();
Car updatedCar = dynamoDbEnhancedClient.table("Car", TableSchema.fromBean(Car.class))
.updateItem(car);
assertEquals("black", updatedCar.getColor()); // PASS
assertEquals("2020", updatedCar.getYear()); // FAIL
assertEquals("Ford Mustang", updatedCar.getModel()); // FAIL
Reproduction Steps
- Create a
Car
table with fields vin (primary key), year, model, color - Create Java class named as Car
- Add class level annotation
@DynamoDbBean
- Add
@DynamoDbPartitionKey
annotation to a getter method of vin - Add a new record in Car table as mentioned in Current Behavior
- Create an instance of
dynamoDbEnhancedClient
- Execute code snippet as mentioned in Current Behavior
Possible Solution
- updateItem should only affect the values in the input
- This begs a question what should happen to the default values which are assigned as
null
. There is a field level annotation for ignoring null (it didn't work for me either). Also, need a class level annotation for ignoring all null fields.
Additional Information/Context
- Springboot 3.1.5
- Java 21
- AWS SDK 2.20.153
- spring-cloud-aws-starter-dynamodb 3.0.2
AWS Java SDK version used
2.20.153
JDK version used
21
Operating System and version
Windows 11 Pro x64