Skip to content

DynamoDB Enhanced Client : Nested documents in collections not working correctly in BeanTableSchema #1748

Closed
@bmaizels

Description

@bmaizels

Describe the bug

BeanTableSchema does not correctly convert document beans when they are used in a collection (eg: List, Map<String, DocumentBean>).

Expected Behavior

These items should be converted correctly.

Current Behavior

An exception is thrown stating a converter cannot be found for the DocumentBean class.

Repro

    @Test
    public void documentBean_list_correctlyMapsAttributes() {
        BeanTableSchema<DocumentBean> beanTableSchema = BeanTableSchema.create(DocumentBean.class);
        AbstractBean abstractBean1 = new AbstractBean();
        abstractBean1.setAttribute2("two");
        AbstractBean abstractBean2 = new AbstractBean();
        abstractBean2.setAttribute2("three");
        DocumentBean documentBean = new DocumentBean();
        documentBean.setId("id-value");
        documentBean.setAttribute1("one");
        documentBean.setAbstractBeanList(Arrays.asList(abstractBean1, abstractBean2));

        AttributeValue expectedDocument1 = AttributeValue.builder()
                                                        .m(singletonMap("attribute2", stringValue("two")))
                                                        .build();
        AttributeValue expectedDocument2 = AttributeValue.builder()
                                                         .m(singletonMap("attribute2", stringValue("three")))
                                                         .build();
        AttributeValue expectedList = AttributeValue.builder().l(expectedDocument1, expectedDocument2).build();

        Map<String, AttributeValue> itemMap = beanTableSchema.itemToMap(documentBean, false);
        assertThat(itemMap.size(), is(3));
        assertThat(itemMap, hasEntry("id", stringValue("id-value")));
        assertThat(itemMap, hasEntry("attribute1", stringValue("one")));
        assertThat(itemMap, hasEntry("abstractBeanList", expectedList));
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions