@Target(value=METHOD) @Retention(value=RUNTIME) public @interface DynamoDbIgnoreNulls
TableSchema.itemToMap(Object, boolean)
, a separate DynamoDB object that is
stored in the current object should ignore the attributes with null values. Note that if this annotation is absent, NULL
attributes will be created.
Example using DynamoDbIgnoreNulls
:
@DynamoDbBean
public class NestedBean {
private AbstractBean innerBean1;
private AbstractBean innerBean2;
@DynamoDbIgnoreNulls
public AbstractBean getInnerBean1() {
return innerBean1;
}
public void setInnerBean1(AbstractBean innerBean) {
this.innerBean1 = innerBean;
}
public AbstractBean getInnerBean2() {
return innerBean;
}
public void setInnerBean2(AbstractBean innerBean) {
this.innerBean2 = innerBean;
}
}
BeanTableSchema beanTableSchema = BeanTableSchema.create(NestedBean.class);
AbstractBean innerBean1 = new AbstractBean();
AbstractBean innerBean2 = new AbstractBean();
NestedBean bean = new NestedBean();
bean.setInnerBean1(innerBean1);
bean.setInnerBean2(innerBean2);
Map itemMap = beanTableSchema.itemToMap(bean, true);
// innerBean1 w/ @DynamoDbIgnoreNulls does not have any attribute values because all the fields are null
assertThat(itemMap.get("innerBean1").m(), empty());
// innerBean2 w/o @DynamoDbIgnoreNulls has a NULLL attribute.
assertThat(nestedBean.getInnerBean2(), hasEntry("attribute", nullAttributeValue()));
Copyright © 2022. All rights reserved.