Skip to content

Revert "Fixed DynamoDbEnhancedClient TableSchema::itemToMap to handle flattened members when ignoreNulls is false (#5832) #6037

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private B mapToItem(B thisBuilder,
private Map<String, AttributeValue> itemToMap(T item, boolean ignoreNulls) {
T1 otherItem = this.otherItemGetter.apply(item);

if (otherItem == null && ignoreNulls) {
if (otherItem == null) {
return Collections.emptyMap();
}

Expand Down Expand Up @@ -515,9 +515,7 @@ public Map<String, AttributeValue> itemToMap(T item, boolean ignoreNulls) {

attributeMappers.forEach(attributeMapper -> {
String attributeKey = attributeMapper.attributeName();
AttributeValue attributeValue = item == null ?
AttributeValue.fromNul(true) :
attributeMapper.attributeGetterMethod().apply(item);
AttributeValue attributeValue = attributeMapper.attributeGetterMethod().apply(item);

if (!ignoreNulls || !isNullAttributeValue(attributeValue)) {
attributeValueMap.put(attributeKey, attributeValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import software.amazon.awssdk.enhanced.dynamodb.internal.AttributeValues;
import software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans.AbstractBean;
import software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans.AbstractImmutable;
import software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans.AbstractNestedImmutable;
import software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans.AttributeConverterBean;
import software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans.AttributeConverterNoConstructorBean;
import software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans.CommonTypesBean;
Expand All @@ -56,7 +55,6 @@
import software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans.ExtendedBean;
import software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans.FlattenedBeanBean;
import software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans.FlattenedImmutableBean;
import software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans.FlattenedNestedImmutableBean;
import software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans.FluentSetterBean;
import software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans.IgnoredAttributeBean;
import software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans.InvalidBean;
Expand Down Expand Up @@ -259,67 +257,6 @@ public void dynamoDbFlatten_correctlyFlattensImmutableAttributes() {
assertThat(itemMap, hasEntry("attribute2", stringValue("two")));
}

@Test
public void dynamoDbFlatten_correctlyFlattensNullImmutableAttributes() {
BeanTableSchema<FlattenedImmutableBean> beanTableSchema = BeanTableSchema.create(FlattenedImmutableBean.class);
AbstractImmutable abstractImmutable = AbstractImmutable.builder().build();
FlattenedImmutableBean flattenedImmutableBean = new FlattenedImmutableBean();
flattenedImmutableBean.setId("id-value");
flattenedImmutableBean.setAbstractImmutable(abstractImmutable);

Map<String, AttributeValue> itemMap = beanTableSchema.itemToMap(flattenedImmutableBean, false);
assertThat(itemMap.size(), is(3));
assertThat(itemMap, hasEntry("id", stringValue("id-value")));
assertThat(itemMap, hasEntry("attribute1", AttributeValue.fromNul(true)));
assertThat(itemMap, hasEntry("attribute2", AttributeValue.fromNul(true)));
}

@Test
public void dynamoDbFlatten_correctlyFlattensNestedImmutableAttributes() {
BeanTableSchema<FlattenedNestedImmutableBean> beanTableSchema =
BeanTableSchema.create(FlattenedNestedImmutableBean.class);
AbstractNestedImmutable abstractNestedImmutable2 =
AbstractNestedImmutable.builder().attribute2("nested-two").build();
AbstractNestedImmutable abstractNestedImmutable1 =
AbstractNestedImmutable.builder().attribute2("two").abstractNestedImmutableOne(abstractNestedImmutable2).build();
FlattenedNestedImmutableBean flattenedNestedImmutableBean = new FlattenedNestedImmutableBean();
flattenedNestedImmutableBean.setId("id-value");
flattenedNestedImmutableBean.setAttribute1("one");
flattenedNestedImmutableBean.setAbstractNestedImmutable(abstractNestedImmutable1);

Map<String, AttributeValue> nestedAttributesMap = new HashMap<>();
nestedAttributesMap.put("abstractNestedImmutableOne", AttributeValue.fromNul(true));
nestedAttributesMap.put("attribute2", stringValue("nested-two"));

AttributeValue expectedNestedAttribute =
AttributeValue.builder().m(Collections.unmodifiableMap(nestedAttributesMap)).build();

Map<String, AttributeValue> itemMap = beanTableSchema.itemToMap(flattenedNestedImmutableBean, false);
assertThat(itemMap.size(), is(4));
assertThat(itemMap, hasEntry("id", stringValue("id-value")));
assertThat(itemMap, hasEntry("attribute1", stringValue("one")));
assertThat(itemMap, hasEntry("attribute2", stringValue("two")));
assertThat(itemMap, hasEntry("abstractNestedImmutableOne", expectedNestedAttribute));
}

@Test
public void dynamoDbFlatten_correctlyFlattensNullNestedImmutableAttributes() {
BeanTableSchema<FlattenedNestedImmutableBean> beanTableSchema =
BeanTableSchema.create(FlattenedNestedImmutableBean.class);
AbstractNestedImmutable abstractNestedImmutable = AbstractNestedImmutable.builder().build();
FlattenedNestedImmutableBean flattenedNestedImmutableBean = new FlattenedNestedImmutableBean();
flattenedNestedImmutableBean.setId("id-value");
flattenedNestedImmutableBean.setAttribute1("one");
flattenedNestedImmutableBean.setAbstractNestedImmutable(abstractNestedImmutable);

Map<String, AttributeValue> itemMap = beanTableSchema.itemToMap(flattenedNestedImmutableBean, false);
assertThat(itemMap.size(), is(4));
assertThat(itemMap, hasEntry("id", stringValue("id-value")));
assertThat(itemMap, hasEntry("attribute1", stringValue("one")));
assertThat(itemMap, hasEntry("attribute2", AttributeValue.fromNul(true)));
assertThat(itemMap, hasEntry("abstractNestedImmutableOne", AttributeValue.fromNul(true)));
}

@Test
public void documentBean_correctlyMapsBeanAttributes() {
BeanTableSchema<DocumentBean> beanTableSchema = BeanTableSchema.create(DocumentBean.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1388,24 +1388,6 @@ public void buildAbstractWithFlatten() {
is(singletonMap("documentString", AttributeValue.builder().s("test-string").build())));
}

@Test
public void buildAbstractWithFlattenAndIgnoreNullAsFalse() {
StaticTableSchema<FakeMappedItem> tableSchema =
StaticTableSchema.builder(FakeMappedItem.class)
.flatten(FAKE_DOCUMENT_TABLE_SCHEMA,
FakeMappedItem::getAFakeDocument,
FakeMappedItem::setAFakeDocument)
.build();

FakeDocument document = FakeDocument.of("test-string", null);
FakeMappedItem item = FakeMappedItem.builder().aFakeDocument(document).build();

Map<String, AttributeValue> attributeMapWithNulls = tableSchema.itemToMap(item, false);
assertThat(attributeMapWithNulls.size(), is(2));
assertThat(attributeMapWithNulls, hasEntry("documentString", AttributeValue.builder().s("test-string").build()));
assertThat(attributeMapWithNulls, hasEntry("documentInteger", AttributeValue.fromNul(true)));
}

@Test
public void buildAbstractExtends() {
StaticTableSchema<FakeAbstractSuperclass> superclassTableSchema =
Expand Down

This file was deleted.

This file was deleted.

Loading