diff --git a/.changes/next-release/bugfix-AmazonDynamoDBEnhancedClient-752432f.json b/.changes/next-release/bugfix-AmazonDynamoDBEnhancedClient-752432f.json new file mode 100644 index 000000000000..61178de8b2b5 --- /dev/null +++ b/.changes/next-release/bugfix-AmazonDynamoDBEnhancedClient-752432f.json @@ -0,0 +1,6 @@ +{ + "type": "bugfix", + "category": "Amazon DynamoDB Enhanced Client", + "contributor": "", + "description": "Fixed DynamoDbEnhancedClient TableSchema::itemToMap to return a map that contains a consistent representation of null top-level (non-flattened) attributes and flattened attributes when their enclosing member is null and ignoreNulls is set to false." +} diff --git a/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/mapper/StaticImmutableTableSchema.java b/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/mapper/StaticImmutableTableSchema.java index ea86ac9fcec4..e5518e520479 100644 --- a/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/mapper/StaticImmutableTableSchema.java +++ b/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/mapper/StaticImmutableTableSchema.java @@ -126,7 +126,7 @@ private B mapToItem(B thisBuilder, private Map itemToMap(T item, boolean ignoreNulls) { T1 otherItem = this.otherItemGetter.apply(item); - if (otherItem == null) { + if (otherItem == null && ignoreNulls) { return Collections.emptyMap(); } @@ -515,7 +515,9 @@ public Map itemToMap(T item, boolean ignoreNulls) { attributeMappers.forEach(attributeMapper -> { String attributeKey = attributeMapper.attributeName(); - AttributeValue attributeValue = attributeMapper.attributeGetterMethod().apply(item); + AttributeValue attributeValue = item == null ? + AttributeValue.fromNul(true) : + attributeMapper.attributeGetterMethod().apply(item); if (!ignoreNulls || !isNullAttributeValue(attributeValue)) { attributeValueMap.put(attributeKey, attributeValue); @@ -523,7 +525,11 @@ public Map itemToMap(T item, boolean ignoreNulls) { }); indexedFlattenedMappers.forEach((name, flattenedMapper) -> { - attributeValueMap.putAll(flattenedMapper.itemToMap(item, ignoreNulls)); + if (item != null) { + attributeValueMap.putAll(flattenedMapper.itemToMap(item, ignoreNulls)); + } else if (!ignoreNulls) { + attributeValueMap.put(name, AttributeValue.fromNul(true)); + } }); return unmodifiableMap(attributeValueMap); diff --git a/services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/BeanTableSchemaTest.java b/services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/BeanTableSchemaTest.java index 275ab2f8d423..3d5f8ab2ebe9 100644 --- a/services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/BeanTableSchemaTest.java +++ b/services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/BeanTableSchemaTest.java @@ -45,6 +45,7 @@ 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; @@ -54,7 +55,10 @@ import software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans.EnumBean; 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.FlattenedFirstNestedBean; +import software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans.FlattenedFirstNestedBean.FlattenedSecondNestedBean; 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; @@ -257,6 +261,128 @@ public void dynamoDbFlatten_correctlyFlattensImmutableAttributes() { assertThat(itemMap, hasEntry("attribute2", stringValue("two"))); } + @Test + public void dynamoDbFlatten_correctlyFlattensNullImmutableAttributes() { + BeanTableSchema beanTableSchema = BeanTableSchema.create(FlattenedImmutableBean.class); + AbstractImmutable abstractImmutable = AbstractImmutable.builder().build(); + FlattenedImmutableBean flattenedImmutableBean = new FlattenedImmutableBean(); + flattenedImmutableBean.setId("id-value"); + flattenedImmutableBean.setAbstractImmutable(abstractImmutable); + + Map 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 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 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 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 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 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 dynamoDbFlatten_correctlyFlattensSecondNullNestedAttributes_IgnoreNullsFalse() { + BeanTableSchema beanTableSchema = + BeanTableSchema.create(FlattenedFirstNestedBean.class); + FlattenedFirstNestedBean flattenedFirstNestedBean = new FlattenedFirstNestedBean(); + flattenedFirstNestedBean.setId("id-value"); + + Map itemMap = beanTableSchema.itemToMap(flattenedFirstNestedBean, false); + assertThat(itemMap.size(), is(4)); + assertThat(itemMap, hasEntry("id", stringValue("id-value"))); + assertThat(itemMap, hasEntry("secondId", AttributeValue.fromNul(true))); + assertThat(itemMap, hasEntry("thirdId", AttributeValue.fromNul(true))); + assertThat(itemMap, hasEntry("flattenedFourthBean", AttributeValue.fromNul(true))); + } + + @Test + public void dynamoDbFlatten_correctlyFlattensSecondNullNestedAttributes_IgnoreNullsTrue() { + BeanTableSchema beanTableSchema = + BeanTableSchema.create(FlattenedFirstNestedBean.class); + FlattenedFirstNestedBean flattenedFirstNestedBean = new FlattenedFirstNestedBean(); + flattenedFirstNestedBean.setId("id-value"); + + Map itemMap = beanTableSchema.itemToMap(flattenedFirstNestedBean, true); + assertThat(itemMap.size(), is(1)); + assertThat(itemMap, hasEntry("id", stringValue("id-value"))); + } + + @Test + public void dynamoDbFlatten_correctlyFlattensThirdNullNestedAttributes_IgnoreNullsFalse() { + BeanTableSchema beanTableSchema = + BeanTableSchema.create(FlattenedFirstNestedBean.class); + FlattenedSecondNestedBean flattenedSecondNestedBean = new FlattenedSecondNestedBean(); + flattenedSecondNestedBean.setSecondId("second-id-value"); + FlattenedFirstNestedBean flattenedFirstNestedBean = new FlattenedFirstNestedBean(); + flattenedFirstNestedBean.setId("id-value"); + flattenedFirstNestedBean.setFlattenedSecondNestedBean(flattenedSecondNestedBean); + + Map itemMap = beanTableSchema.itemToMap(flattenedFirstNestedBean, false); + assertThat(itemMap.size(), is(4)); + assertThat(itemMap, hasEntry("id", stringValue("id-value"))); + assertThat(itemMap, hasEntry("secondId", stringValue("second-id-value"))); + assertThat(itemMap, hasEntry("thirdId", AttributeValue.fromNul(true))); + assertThat(itemMap, hasEntry("flattenedFourthBean", AttributeValue.fromNul(true))); + } + + @Test + public void dynamoDbFlatten_correctlyFlattensThirdNullNestedAttributes_IgnoreNullsTrue() { + BeanTableSchema beanTableSchema = + BeanTableSchema.create(FlattenedFirstNestedBean.class); + FlattenedSecondNestedBean flattenedSecondNestedBean = new FlattenedSecondNestedBean(); + flattenedSecondNestedBean.setSecondId("second-id-value"); + FlattenedFirstNestedBean flattenedFirstNestedBean = new FlattenedFirstNestedBean(); + flattenedFirstNestedBean.setId("id-value"); + flattenedFirstNestedBean.setFlattenedSecondNestedBean(flattenedSecondNestedBean); + + Map itemMap = beanTableSchema.itemToMap(flattenedFirstNestedBean, true); + assertThat(itemMap.size(), is(2)); + assertThat(itemMap, hasEntry("id", stringValue("id-value"))); + assertThat(itemMap, hasEntry("secondId", stringValue("second-id-value"))); + } + @Test public void documentBean_correctlyMapsBeanAttributes() { BeanTableSchema beanTableSchema = BeanTableSchema.create(DocumentBean.class); diff --git a/services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/StaticImmutableTableSchemaTest.java b/services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/StaticImmutableTableSchemaTest.java index 5c1b8b2a4d11..10377782772a 100644 --- a/services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/StaticImmutableTableSchemaTest.java +++ b/services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/StaticImmutableTableSchemaTest.java @@ -59,6 +59,7 @@ import software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem; import software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemComposedClass; import software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithSort; +import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbFlatten; import software.amazon.awssdk.enhanced.dynamodb.mapper.testimmutables.EntityEnvelopeImmutable; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; @@ -782,6 +783,62 @@ public Consumer modifyMetadata() { } } + public static final class FakeMappedItemWithDeep { + private String documentString; + private FakeDocumentWithDeep aFakeDocument; + + public String getDocumentString() { + return documentString; + } + + public void setDocumentString(String documentString) { + this.documentString = documentString; + } + + @DynamoDbFlatten + public FakeDocumentWithDeep getAFakeDocument() { + return aFakeDocument; + } + + public void setAFakeDocument(FakeDocumentWithDeep aFakeDocument) { + this.aFakeDocument = aFakeDocument; + } + } + + public static final class FakeDocumentWithDeep { + private Integer documentInteger; + private DeepFakeDocument deepFakeDocument; + + public Integer getDocumentInteger() { + return documentInteger; + } + + public void setDocumentInteger(Integer documentInteger) { + this.documentInteger = documentInteger; + } + + @DynamoDbFlatten + public DeepFakeDocument getDeepFakeDocument() { + return deepFakeDocument; + } + + public void setDeepFakeDocument(DeepFakeDocument deepFakeDocument) { + this.deepFakeDocument = deepFakeDocument; + } + } + + public static final class DeepFakeDocument { + private String deepString; + + public String getDeepString() { + return deepString; + } + + public void setDeepString(String deepString) { + this.deepString = deepString; + } + } + @Mock private AttributeConverterProvider provider1; @@ -1388,6 +1445,67 @@ public void buildAbstractWithFlatten() { is(singletonMap("documentString", AttributeValue.builder().s("test-string").build()))); } + @Test + public void buildAbstractWithFlattenAndIgnoreNullAsFalse() { + StaticTableSchema 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 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 buildAbstractWithNestedFlattenAndIgnoreNullAsFalse() { + StaticTableSchema deepSchema = + StaticTableSchema.builder(DeepFakeDocument.class) + .newItemSupplier(DeepFakeDocument::new) + .addAttribute(String.class, a -> a.name("deepString") + .getter(DeepFakeDocument::getDeepString) + .setter(DeepFakeDocument::setDeepString)) + .build(); + + StaticTableSchema nestedSchema = + StaticTableSchema.builder(FakeDocumentWithDeep.class) + .newItemSupplier(FakeDocumentWithDeep::new) + .addAttribute(Integer.class, a -> a.name("documentInteger") + .getter(FakeDocumentWithDeep::getDocumentInteger) + .setter(FakeDocumentWithDeep::setDocumentInteger)) + .flatten(deepSchema, + FakeDocumentWithDeep::getDeepFakeDocument, + FakeDocumentWithDeep::setDeepFakeDocument) + .build(); + + StaticTableSchema tableSchema = + StaticTableSchema.builder(FakeMappedItemWithDeep.class) + .newItemSupplier(FakeMappedItemWithDeep::new) + .addAttribute(String.class, a -> a.name("documentString") + .getter(FakeMappedItemWithDeep::getDocumentString) + .setter(FakeMappedItemWithDeep::setDocumentString)) + .flatten(nestedSchema, + FakeMappedItemWithDeep::getAFakeDocument, + FakeMappedItemWithDeep::setAFakeDocument) + .build(); + + FakeMappedItemWithDeep item = new FakeMappedItemWithDeep(); + item.setDocumentString("top-level-string"); + + Map attributeMap = tableSchema.itemToMap(item, false); + + assertThat(attributeMap.size(), is(3)); + assertThat(attributeMap, hasEntry("documentString", AttributeValue.builder().s("top-level-string").build())); + assertThat(attributeMap, hasEntry("documentInteger", AttributeValue.fromNul(true))); + assertThat(attributeMap, hasEntry("deepString", AttributeValue.fromNul(true))); + } + @Test public void buildAbstractExtends() { StaticTableSchema superclassTableSchema = diff --git a/services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/testbeans/AbstractNestedImmutable.java b/services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/testbeans/AbstractNestedImmutable.java new file mode 100644 index 000000000000..12b1d0bbf79b --- /dev/null +++ b/services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/testbeans/AbstractNestedImmutable.java @@ -0,0 +1,85 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans; + +import java.util.Objects; +import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbImmutable; + +@DynamoDbImmutable(builder = AbstractNestedImmutable.Builder.class) +public class AbstractNestedImmutable { + private final String attribute2; + private final AbstractNestedImmutable abstractNestedImmutableOne; + + private AbstractNestedImmutable(Builder b) { + this.attribute2 = b.attribute2; + this.abstractNestedImmutableOne = b.abstractNestedImmutableOne; + } + + public String attribute2() { + return attribute2; + } + + public AbstractNestedImmutable abstractNestedImmutableOne() { + return abstractNestedImmutableOne; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + AbstractNestedImmutable that = (AbstractNestedImmutable) o; + + if (!Objects.equals(attribute2, that.attribute2)) { + return false; + } + return Objects.equals(abstractNestedImmutableOne, that.abstractNestedImmutableOne); + } + + @Override + public int hashCode() { + int result = attribute2 != null ? attribute2.hashCode() : 0; + result = 31 * result + (abstractNestedImmutableOne != null ? abstractNestedImmutableOne.hashCode() : 0); + return result; + } + + public static Builder builder() { + return new Builder(); + } + + public static final class Builder { + private String attribute2; + private AbstractNestedImmutable abstractNestedImmutableOne; + + public Builder attribute2(String attribute2) { + this.attribute2 = attribute2; + return this; + } + + public Builder abstractNestedImmutableOne(AbstractNestedImmutable abstractNestedImmutableOne) { + this.abstractNestedImmutableOne = abstractNestedImmutableOne; + return this; + } + + public AbstractNestedImmutable build() { + return new AbstractNestedImmutable(this); + } + } +} \ No newline at end of file diff --git a/services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/testbeans/FlattenedFirstNestedBean.java b/services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/testbeans/FlattenedFirstNestedBean.java new file mode 100644 index 000000000000..ce08a8379b0f --- /dev/null +++ b/services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/testbeans/FlattenedFirstNestedBean.java @@ -0,0 +1,99 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans; + +import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbBean; +import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbFlatten; +import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbPartitionKey; + +@DynamoDbBean +public class FlattenedFirstNestedBean { + private String id; + private FlattenedSecondNestedBean flattenedSecondNestedBean; + + @DynamoDbFlatten + public FlattenedSecondNestedBean getFlattenedSecondNestedBean() { + return flattenedSecondNestedBean; + } + + public void setFlattenedSecondNestedBean(FlattenedSecondNestedBean flattenedSecondNestedBean) { + this.flattenedSecondNestedBean = flattenedSecondNestedBean; + } + + @DynamoDbPartitionKey + public String getId() { + return this.id; + } + + public void setId(String id) { + this.id = id; + } + + @DynamoDbBean + public static class FlattenedSecondNestedBean { + private FlattenedThirdNestedBean flattenedThirdNestedBean; + private String secondId; + + @DynamoDbFlatten + public FlattenedThirdNestedBean getFlattenedThirdNestedBean() { + return flattenedThirdNestedBean; + } + + public void setFlattenedThirdNestedBean(FlattenedThirdNestedBean flattenedThirdNestedBean) { + this.flattenedThirdNestedBean = flattenedThirdNestedBean; + } + + public String getSecondId() { + return secondId; + } + + public void setSecondId(String secondId) { + this.secondId = secondId; + } + } + + public enum FlattenedFourthBean { + SUCCESS, + FAILED + } + + @DynamoDbBean + public static class FlattenedThirdNestedBean { + private FlattenedFourthBean flattenedFourthBean; + private String thirdId; + + public FlattenedThirdNestedBean() { + this.flattenedFourthBean = FlattenedFourthBean.SUCCESS; + } + + public FlattenedFourthBean getFlattenedFourthBean() { + return flattenedFourthBean; + } + + public void setFlattenedFourthBean(FlattenedFourthBean flattenedFourthBean) { + this.flattenedFourthBean = flattenedFourthBean; + } + + public String getThirdId() { + return thirdId; + } + + public void setThirdId(String thirdId) { + this.thirdId = thirdId; + } + } + +} diff --git a/services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/testbeans/FlattenedNestedImmutableBean.java b/services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/testbeans/FlattenedNestedImmutableBean.java new file mode 100644 index 000000000000..9b0bf9724dd4 --- /dev/null +++ b/services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/testbeans/FlattenedNestedImmutableBean.java @@ -0,0 +1,53 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package software.amazon.awssdk.enhanced.dynamodb.mapper.testbeans; + +import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbBean; +import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbFlatten; +import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbPartitionKey; + +@DynamoDbBean +public class FlattenedNestedImmutableBean { + private String id; + private String attribute1; + private AbstractNestedImmutable abstractNestedImmutable; + + @DynamoDbPartitionKey + public String getId() { + return this.id; + } + + public void setId(String id) { + this.id = id; + } + + public String getAttribute1() { + return attribute1; + } + + public void setAttribute1(String attribute1) { + this.attribute1 = attribute1; + } + + @DynamoDbFlatten + public AbstractNestedImmutable getAbstractNestedImmutable() { + return abstractNestedImmutable; + } + + public void setAbstractNestedImmutable(AbstractNestedImmutable abstractNestedImmutable) { + this.abstractNestedImmutable = abstractNestedImmutable; + } +} \ No newline at end of file