Open
Description
Describe the bug
When calling converterForAttribute
on a StaticImmutableTableSchema
where an attributes which is flattened in from another schema using StaticImmutableTableSchema.Builder.flatten
, no converter is returned.
I think this is because the indexedMappers
is used instead of the combination of indexedMappers
and indexedFlattenedMappers
.
Expected Behavior
The correct AttributeConverter
for the any attribute of an item, regardless of how the schema was built.
Current Behavior
No AttributeConverter
is returned.
Reproduction Steps
import static software.amazon.awssdk.enhanced.dynamodb.mapper.StaticAttributeTags.primaryPartitionKey;
import java.util.Objects;
import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema;
class Scratch {
public static void main(String[] args) {
var innerSchema = StaticImmutableTableSchema.builder(Inner.class, Inner.Builder.class)
.addAttribute(String.class, a -> a.name("InnerAttribute")
.getter(Inner::innerAttribute)
.setter(Inner.Builder::innerAttribute))
.newItemBuilder(Inner.Builder::new, Inner.Builder::build)
.build();
var outerSchema = StaticImmutableTableSchema.builder(Outer.class, Outer.Builder.class)
.addAttribute(String.class, a -> a.name("PK")
.getter(Outer::partitionKey)
.setter(Outer.Builder::partitionKey)
.tags(primaryPartitionKey()))
.flatten(innerSchema, Outer::inner, Outer.Builder::inner)
.newItemBuilder(Outer.Builder::new, Outer.Builder::build)
.build();
Objects.requireNonNull(outerSchema.converterForAttribute("PK"),
"converterForAttribute for PK should not be null");
Objects.requireNonNull(innerSchema.converterForAttribute("InnerAttribute"),
"converterForAttribute for InnerAttribute from innerSchema should not be null");
if (!outerSchema.attributeNames().contains("InnerAttribute")) {
throw new IllegalStateException("attributeNames for outerSchema should contain InnerAttribute");
}
Objects.requireNonNull(outerSchema.converterForAttribute("InnerAttribute"),
"converterForAttribute for InnerAttribute from outerSchema should not be null");
}
public static class Outer {
public Outer(Inner inner, String partitionKey) {
this.inner = inner;
this.partitionKey = partitionKey;
}
public Inner inner() {
return inner;
}
public String partitionKey() {
return partitionKey;
}
private final Inner inner;
private final String partitionKey;
public static class Builder {
public Builder inner(Inner inner) {
this.inner = inner;
return this;
}
public Builder partitionKey(String partitionKey) {
this.partitionKey = partitionKey;
return this;
}
public Outer build() {
return new Outer(inner, partitionKey);
}
private Inner inner;
private String partitionKey;
}
}
public static class Inner {
public Inner(String innerAttribute) {
this.innerAttribute = innerAttribute;
}
public String innerAttribute() {
return innerAttribute;
}
private final String innerAttribute;
public static class Builder {
public Builder innerAttribute(String innerAttribute) {
this.innerAttribute = innerAttribute;
return this;
}
public Inner build() {
return new Inner(innerAttribute);
}
private String innerAttribute;
}
}
}
Possible Solution
No response
Additional Information/Context
Using version 2.17.162
AWS Java SDK version used
17.0.1
JDK version used
17.0.1
Operating System and version
macOS 12.2.1