Annotation Type DynamoDbPreserveEmptyObject
Specifies that when calling
TableSchema.mapToItem(Map)
, a separate DynamoDB object that is stored in the current
object should be initialized as empty class if all fields in this class are null. Note that if this annotation is absent,
the object will be null.
Example using DynamoDbPreserveEmptyObject
:
@DynamoDbBean public class NestedBean { private AbstractBean innerBean1; private AbstractBean innerBean2; @DynamoDbPreserveEmptyObject 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<NestedBean> beanTableSchema = BeanTableSchema.create(NestedBean.class); AbstractBean innerBean1 = new AbstractBean(); AbstractBean innerBean2 = new AbstractBean(); NestedBean bean = new NestedBean(); bean.setInnerBean1(innerBean1); bean.setInnerBean2(innerBean2); Map<String, AttributeValue> itemMap = beanTableSchema.itemToMap(bean, true); NestedBean nestedBean = beanTableSchema.mapToItem(itemMap); // innerBean1 w/ @DynamoDbPreserveEmptyObject is mapped to empty object assertThat(nestedBean.getInnerBean1(), is(innerBean1)); // innerBean2 w/o @DynamoDbPreserveEmptyObject is mapped to null. assertThat(nestedBean.getInnerBean2(), isNull());