|
15 | 15 |
|
16 | 16 | package software.amazon.awssdk.enhanced.dynamodb.mapper;
|
17 | 17 |
|
| 18 | +import static java.util.Collections.emptyMap; |
18 | 19 | import static java.util.Collections.singletonMap;
|
19 | 20 | import static org.hamcrest.MatcherAssert.assertThat;
|
20 | 21 | import static org.hamcrest.Matchers.contains;
|
|
29 | 30 |
|
30 | 31 | import java.nio.charset.StandardCharsets;
|
31 | 32 | import java.util.Arrays;
|
| 33 | +import java.util.Collections; |
32 | 34 | import java.util.HashMap;
|
33 | 35 | import java.util.LinkedHashSet;
|
34 | 36 | import java.util.Map;
|
@@ -205,6 +207,25 @@ public void dynamoDbIgnoreNulls_shouldOmitNulls() {
|
205 | 207 | assertThat(itemMap.get("innerBean2").m(), hasEntry("attribute2", nullAttributeValue()));
|
206 | 208 | }
|
207 | 209 |
|
| 210 | + @Test |
| 211 | + public void dynamoDbIgnoreNulls_onList_shouldOmitNulls() { |
| 212 | + BeanTableSchema<NestedBeanIgnoreNulls> beanTableSchema = BeanTableSchema.create(NestedBeanIgnoreNulls.class); |
| 213 | + NestedBeanIgnoreNulls bean = new NestedBeanIgnoreNulls(); |
| 214 | + |
| 215 | + bean.setInnerBeanList1(Collections.singletonList(new AbstractBean())); |
| 216 | + bean.setInnerBeanList2(Collections.singletonList(new AbstractBean())); |
| 217 | + |
| 218 | + Map<String, AttributeValue> itemMap = beanTableSchema.itemToMap(bean, true); |
| 219 | + AttributeValue expectedMapForInnerBean1 = AttributeValue.builder().l(l -> l.m(emptyMap())).build(); |
| 220 | + AttributeValue expectedMapForInnerBean2 = AttributeValue.builder() |
| 221 | + .l(l -> l.m(singletonMap("attribute2", nullAttributeValue()))) |
| 222 | + .build(); |
| 223 | + |
| 224 | + assertThat(itemMap.size(), is(2)); |
| 225 | + assertThat(itemMap, hasEntry("innerBeanList1", expectedMapForInnerBean1)); |
| 226 | + assertThat(itemMap, hasEntry("innerBeanList2", expectedMapForInnerBean2)); |
| 227 | + } |
| 228 | + |
208 | 229 | @Test
|
209 | 230 | public void dynamoDbFlatten_correctlyFlattensImmutableAttributes() {
|
210 | 231 | BeanTableSchema<FlattenedImmutableBean> beanTableSchema = BeanTableSchema.create(FlattenedImmutableBean.class);
|
|
0 commit comments