Annotation Type DynamoDbImmutable
Class level annotation that identifies this class as being a DynamoDb mappable entity. Any class used to initialize
a
ImmutableTableSchema
must have this annotation. If a class is used as an attribute type within another
annotated DynamoDb class, either as a document or flattened with the DynamoDbFlatten
annotation, it will also
require this annotation to work automatically without an explicit AttributeConverter
.
Attribute Converter Providers
Using AttributeConverterProvider
s is optional and, if used, the supplied provider supersedes the default
converter provided by the table schema.
Note:
- The converter(s) must provide
AttributeConverter
s for all types used in the schema. - The table schema DefaultAttributeConverterProvider provides standard converters for most primitive and common Java types. Use custom AttributeConverterProviders when you have specific needs for type conversion that the defaults do not cover.
- If you provide a list of attribute converter providers, you can add DefaultAttributeConverterProvider to the end of the list to fall back on the defaults.
- Providing an empty list {} will cause no providers to get loaded.
(converterProviders = {CustomAttributeConverter.class, DefaultAttributeConverterProvider.class});
Example using DynamoDbImmutable
:
@DynamoDbImmutable(builder = Customer.Builder.class)
public class Customer {
private final String accountId;
private final int subId;
private final String name;
private final Instant createdDate;
private Customer(Builder b) {
this.accountId = b.accountId;
this.subId = b.subId;
this.name = b.name;
this.createdDate = b.createdDate;
}
// This method will be automatically discovered and used by the TableSchema
public static Builder builder() { return new Builder(); }
@DynamoDbPartitionKey
public String accountId() { return this.accountId; }
@DynamoDbSortKey
public int subId() { return this.subId; }
@DynamoDbSecondaryPartitionKey(indexNames = "customers_by_name")
public String name() { return this.name; }
@DynamoDbSecondarySortKey(indexNames = {"customers_by_date", "customers_by_name"})
public Instant createdDate() { return this.createdDate; }
public static final class Builder {
private String accountId;
private int subId;
private String name;
private Instant createdDate;
private Builder() {}
public Builder accountId(String accountId) { this.accountId = accountId; return this; }
public Builder subId(int subId) { this.subId = subId; return this; }
public Builder name(String name) { this.name = name; return this; }
public Builder createdDate(Instant createdDate) { this.createdDate = createdDate; return this; }
// This method will be automatically discovered and used by the TableSchema
public Customer build() { return new Customer(this); }
}
}
-
Required Element Summary
Required Elements -
Optional Element Summary
Optional Elements
-
Element Details
-
converterProviders
Class<? extends AttributeConverterProvider>[] converterProviders- Default:
{software.amazon.awssdk.enhanced.dynamodb.DefaultAttributeConverterProvider.class}
-
builder
Class<?> builderThe builder class that can be used to construct instances of the annotated immutable class
-