Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When a DynamoDbBean class use primitive types as setter's parameter, it will not be called. #3228

Closed
mikeyan123 opened this issue Jun 1, 2022 · 4 comments
Labels
bug This issue is a bug. documentation This is a problem with documentation. dynamodb-enhanced p3 This is a minor priority issue

Comments

@mikeyan123
Copy link

Describe the bug

As say, I have a order class:
@DynamoDbBean
public class Order {
private Long id;
private Integer amount;

public Order() {
}

public Order(long l, int i) {
	this.id = l;
	this.amount = i;
}

@DynamoDbPartitionKey
public Long getId() {
	return id;
}

public void setId(Long id) {
	this.id = id;
}

public Integer getAmount() {
	return amount;
}

public void setAmount(int amount) {
	this.amount = amount;
}

}
In this class, I use int other than Integer as the parameter of setAmount, strangely, when I try to retrieve the order I put before , the value of amount is null.

class OrderRepositoryTest {

@Autowired
DynamoDbEnhancedClient enhancedClient;

@Test
void findById() {
	DynamoDbTable<Order>  table = enhancedClient.table("order", TableSchema.fromBean(Order.class));
	try {
		table.createTable();
	}
	catch (Exception e){System.out.println(e.getMessage());}
	table.putItem(new Order(1L, 10));
	var order = table.getItem(Key.builder().partitionValue(1L).build());
	assertThat(order.getAmount()).isEqualTo(10);
}

}

Is that a bug?

Expected Behavior

I think even use primitive type as the parameter, it should work, or throw an exception.

Current Behavior

It don't call the setAmount method.

Reproduction Steps

See the code.

Possible Solution

I think even use primitive type as the parameter, it should work, or throw an exception.

Additional Information/Context

No response

AWS Java SDK version used

2.17.201

JDK version used

18

Operating System and version

macOS Monterey 12.4

@mikeyan123 mikeyan123 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 1, 2022
@monika-sivamoorthy
Copy link

Can I work on this bug?

@debora-ito debora-ito added p2 This is a standard priority issue p3 This is a minor priority issue and removed p2 This is a standard priority issue labels Apr 1, 2023
@debora-ito
Copy link
Member

debora-ito commented May 16, 2023

@mikeyan123 apologies for the delay.

Our recommendation is to use non-primitive Java data types only.
Could not find this recommendation in the DynamoDB Enhanced Client documentation, so I'm marking this as a task to improve our docs.

@debora-ito debora-ito added documentation This is a problem with documentation. dynamodb-enhanced and removed needs-triage This issue or PR still needs to be triaged. labels May 16, 2023
@debora-ito
Copy link
Member

This is now addressed in the "Learn the basics of the DynamoDB Enhanced Client API" documentation:

The attribute types (properties) of your Java data classes should be objects types, not primitives. For example, always use Long and Integer object data types, not long and int primitives.

Copy link

github-actions bot commented Aug 2, 2024

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

aws-sdk-java-automation added a commit that referenced this issue Sep 5, 2024
…f7976ef51

Pull request: release <- staging/52e7acc3-909d-418f-9589-da8f7976ef51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. documentation This is a problem with documentation. dynamodb-enhanced p3 This is a minor priority issue
Projects
None yet
Development

No branches or pull requests

3 participants