Interface TableSchema<T>

Type Parameters:
T - The type of model object that is being mapped to records in the DynamoDb table.
All Known Implementing Classes:
BeanTableSchema, DocumentTableSchema, ImmutableTableSchema, MetaTableSchema, StaticImmutableTableSchema, StaticTableSchema, WrappedTableSchema

@SdkPublicApi @ThreadSafe public interface TableSchema<T>
Interface for a mapper that is capable of mapping a modelled Java object into a map of AttributeValue that is understood by the DynamoDb low-level SDK and back again. This object is also expected to know about the structure of the table it is modelling, which is stored in a TableMetadata object.
  • Method Details

    • builder

      static <T> StaticTableSchema.Builder<T> builder(Class<T> itemClass)
      Returns a builder for the StaticTableSchema implementation of this interface which allows all attributes, tags and table structure to be directly declared in the builder.
      Type Parameters:
      T - The type of the item this TableSchema will map records to.
      Parameters:
      itemClass - The class of the item this TableSchema will map records to.
      Returns:
      A newly initialized StaticTableSchema.Builder.
    • builder

      static <T> StaticTableSchema.Builder<T> builder(EnhancedType<T> itemType)
      Returns a builder for the StaticTableSchema implementation of this interface which allows all attributes, tags and table structure to be directly declared in the builder.
      Type Parameters:
      T - The type of the item this TableSchema will map records to.
      Parameters:
      itemType - The EnhancedType of the item this TableSchema will map records to.
      Returns:
      A newly initialized StaticTableSchema.Builder.
    • builder

      static <T, B> StaticImmutableTableSchema.Builder<T,B> builder(Class<T> immutableItemClass, Class<B> immutableBuilderClass)
      Returns a builder for the StaticImmutableTableSchema implementation of this interface which allows all attributes, tags and table structure to be directly declared in the builder.
      Type Parameters:
      T - The type of the immutable item this TableSchema will map records to.
      B - The type of the builder used by this TableSchema to construct immutable items with.
      Parameters:
      immutableItemClass - The class of the immutable item this TableSchema will map records to.
      immutableBuilderClass - The class that can be used to construct immutable items this TableSchema maps records to.
      Returns:
      A newly initialized StaticImmutableTableSchema.Builder
    • builder

      static <T, B> StaticImmutableTableSchema.Builder<T,B> builder(EnhancedType<T> immutableItemType, EnhancedType<B> immutableBuilderType)
      Returns a builder for the StaticImmutableTableSchema implementation of this interface which allows all attributes, tags and table structure to be directly declared in the builder.
      Type Parameters:
      T - The type of the immutable item this TableSchema will map records to.
      B - The type of the builder used by this TableSchema to construct immutable items with.
      Parameters:
      immutableItemType - The EnhancedType of the immutable item this TableSchema will map records to.
      immutableBuilderType - The EnhancedType of the class that can be used to construct immutable items this TableSchema maps records to.
      Returns:
      A newly initialized StaticImmutableTableSchema.Builder
    • fromBean

      static <T> BeanTableSchema<T> fromBean(Class<T> beanClass)
      Scans a bean class that has been annotated with DynamoDb bean annotations and then returns a BeanTableSchema implementation of this interface that can map records to and from items of that bean class.

      It's recommended to only create a BeanTableSchema once for a single bean class, usually at application start up, because it's a moderately expensive operation.

      Type Parameters:
      T - The type of the item this TableSchema will map records to.
      Parameters:
      beanClass - The bean class this TableSchema will map records to.
      Returns:
      An initialized BeanTableSchema.
    • fromBean

      static <T> BeanTableSchema<T> fromBean(BeanTableSchemaParams<T> params)
      Scans a bean class that has been annotated with DynamoDb bean annotations and then returns a BeanTableSchema implementation of this interface that can map records to and from items of that bean class.

      It's recommended to only create a BeanTableSchema once for a single bean class, usually at application start up, because it's a moderately expensive operation.

      Generally, this method should be preferred over fromBean(Class) because it allows you to use a custom MethodHandles.Lookup instance, which is necessary when your application runs in an environment where your application code and dependencies like the AWS SDK for Java are loaded by different classloaders.

      Type Parameters:
      T - The type of the item this TableSchema will map records to.
      Parameters:
      params - The parameters used to create the BeanTableSchema.
      Returns:
      An initialized BeanTableSchema.
    • documentSchemaBuilder

      static DocumentTableSchema.Builder documentSchemaBuilder()
      Provides interfaces to interact with DynamoDB tables as EnhancedDocument where the complete Schema of the table is not required.
      Returns:
      A DocumentTableSchema.Builder for instantiating DocumentTableSchema.
    • fromImmutableClass

      static <T> ImmutableTableSchema<T> fromImmutableClass(Class<T> immutableClass)
      Scans an immutable class that has been annotated with DynamoDb immutable annotations and then returns a ImmutableTableSchema implementation of this interface that can map records to and from items of that immutable class.

      It's recommended to only create an ImmutableTableSchema once for a single immutable class, usually at application start up, because it's a moderately expensive operation.

      Type Parameters:
      T - The type of the item this TableSchema will map records to.
      Parameters:
      immutableClass - The immutable class this TableSchema will map records to.
      Returns:
      An initialized ImmutableTableSchema.
    • fromImmutableClass

      static <T> ImmutableTableSchema<T> fromImmutableClass(ImmutableTableSchemaParams<T> params)
      Scans an immutable class that has been annotated with DynamoDb immutable annotations and then returns a ImmutableTableSchema implementation of this interface that can map records to and from items of that immutable class.

      It's recommended to only create an ImmutableTableSchema once for a single immutable class, usually at application start up, because it's a moderately expensive operation.

      Type Parameters:
      T - The type of the item this TableSchema will map records to.
      Parameters:
      params - The parameters used to create the ImmutableTableSchema.
      Returns:
      An initialized ImmutableTableSchema.
    • fromClass

      static <T> TableSchema<T> fromClass(Class<T> annotatedClass)
      Scans a class that has been annotated with DynamoDb enhanced client annotations and then returns an appropriate TableSchema implementation that can map records to and from items of that class. Currently supported top level annotations (see documentation on those classes for more information on how to use them): DynamoDbBean, DynamoDbImmutable.

      It's recommended to only invoke this operation once for a single class, usually at application start up, because it's a moderately expensive operation.

      If this table schema is not behaving as you expect, enable debug logging for software.amazon.awssdk.enhanced.dynamodb.beans.

      Type Parameters:
      T - The type of the item this TableSchema will map records to.
      Parameters:
      annotatedClass - A class that has been annotated with DynamoDb enhanced client annotations.
      Returns:
      An initialized TableSchema
    • mapToItem

      T mapToItem(Map<String,AttributeValue> attributeMap)
      Takes a raw DynamoDb SDK representation of a record in a table and maps it to a Java object. A new object is created to fulfil this operation.

      If attributes are missing from the map, that will not cause an error, however if attributes are found in the map which the mapper does not know how to map, an exception will be thrown.

      If all attribute values in the attributeMap are null, null will be returned. Use mapToItem(Map, boolean) instead if you need to preserve empty object.

      API Implementors Note:

      mapToItem(Map, boolean) must be implemented if preserveEmptyObject behavior is desired.

      Parameters:
      attributeMap - A map of String to