Skip to content

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

Closed
@mikeyan123

Description

@mikeyan123

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

Activity

added
bugThis issue is a bug.
needs-triageThis issue or PR still needs to be triaged.
on Jun 1, 2022
monika-sivamoorthy

monika-sivamoorthy commented on Jul 18, 2022

@monika-sivamoorthy

Can I work on this bug?

added
p2This is a standard priority issue
p3This is a minor priority issue
and removed
p2This is a standard priority issue
on Apr 1, 2023
debora-ito

debora-ito commented on May 16, 2023

@debora-ito
Member

@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.

added
documentationThis is a problem with documentation.
and removed
needs-triageThis issue or PR still needs to be triaged.
on May 16, 2023
debora-ito

debora-ito commented on Aug 2, 2024

@debora-ito
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.

github-actions

github-actions commented on Aug 2, 2024

@github-actions

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.

added a commit that references this issue on Sep 5, 2024

Merge pull request #3228 from aws/staging/52e7acc3-909d-418f-9589-da8…

e158641
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.documentationThis is a problem with documentation.dynamodb-enhancedp3This is a minor priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @debora-ito@mikeyan123@monika-sivamoorthy

        Issue actions

          When a DynamoDbBean class use primitive types as setter's parameter, it will not be called. · Issue #3228 · aws/aws-sdk-java-v2