Skip to content

Add support for producing EnhancedType with tableSchema from Sets #3014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
Expand Down Expand Up @@ -264,6 +265,12 @@ private static EnhancedType<?> convertTypeToEnhancedType(Type type, MetaTableSch
return EnhancedType.listOf(enhancedType);
}

if (Set.class.equals(rawType)) {
EnhancedType<?> enhancedType = convertTypeToEnhancedType(parameterizedType.getActualTypeArguments()[0],
metaTableSchemaCache, attributeConfiguration);
return EnhancedType.setOf(enhancedType);
}

if (Map.class.equals(rawType)) {
EnhancedType<?> enhancedType = convertTypeToEnhancedType(parameterizedType.getActualTypeArguments()[1],
metaTableSchemaCache, attributeConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -290,6 +291,33 @@ public void documentBean_list_correctlyMapsBeanAttributes() {
assertThat(itemMap, hasEntry("abstractBeanList", expectedList));
}

@Test
public void documentBean_set_correctlyMapsBeanAttributes() {
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.setAbstractBeanSet(new HashSet(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 expectedSet = AttributeValue.builder().l(expectedDocument1, expectedDocument2).build();

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

@Test
public void documentBean_map_correctlyMapsBeanAttributes() {
BeanTableSchema<DocumentBean> beanTableSchema = BeanTableSchema.create(DocumentBean.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.List;
import java.util.Map;
import java.util.Set;
import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbBean;
import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbPartitionKey;

Expand All @@ -30,6 +31,8 @@ public class DocumentBean {
private List<AbstractImmutable> abstractImmutableList;
private Map<String, AbstractBean> abstractBeanMap;
private Map<String, AbstractImmutable> abstractImmutableMap;
private Set<AbstractBean> abstractBeanSet;
private Set<AbstractImmutable> abstractImmutableSet;

@DynamoDbPartitionKey
public String getId() {
Expand Down Expand Up @@ -60,6 +63,13 @@ public void setAbstractBeanList(List<AbstractBean> abstractBeanList) {
this.abstractBeanList = abstractBeanList;
}

public Set<AbstractBean> getAbstractBeanSet() {
return abstractBeanSet;
}
public void setAbstractBeanSet(Set<AbstractBean> abstractBeanSet) {
this.abstractBeanSet = abstractBeanSet;
}

public Map<String, AbstractBean> getAbstractBeanMap() {
return abstractBeanMap;
}
Expand All @@ -81,6 +91,13 @@ public void setAbstractImmutableList(List<AbstractImmutable> abstractImmutableLi
this.abstractImmutableList = abstractImmutableList;
}

public Set<AbstractImmutable> getAbstractImmutableSet() {
return abstractImmutableSet;
}
public void setAbstractImmutableSet(Set<AbstractImmutable> abstractImmutableSet) {
this.abstractImmutableSet = abstractImmutableSet;
}

public Map<String, AbstractImmutable> getAbstractImmutableMap() {
return abstractImmutableMap;
}
Expand Down