Class ListAttributeConverter<T extends Collection<?>>
- All Implemented Interfaces:
AttributeConverter<T>
Collection
type and EnhancedAttributeValue
.
This stores values in DynamoDB as a list of attribute values. This uses a configured AttributeConverter
to convert
the collection contents to an attribute value.
This supports reading a list of attribute values. This uses a configured AttributeConverter
to convert
the collection contents.
A builder is exposed to allow defining how the collection and element types are created and converted:
AttributeConverter<List<Integer>> listConverter =
CollectionAttributeConverter.builder(EnhancedType.listOf(Integer.class))
.collectionConstructor(ArrayList::new)
.elementConverter(IntegerAttributeConverter.create())
.build()
For frequently-used types, static methods are exposed to reduce the amount of boilerplate involved in creation:
AttributeConverter<List<Integer>> listConverter =
CollectionAttributeConverter.listConverter(IntegerAttributeConverter.create());
AttributeConverter<Collection<Integer>> collectionConverer =
CollectionAttributeConverter.collectionConverter(IntegerAttributeConverter.create());
AttributeConverter<Set<Integer>> setConverter =
CollectionAttributeConverter.setConverter(IntegerAttributeConverter.create());
AttributeConverter<SortedSet<Integer>> sortedSetConverter =
CollectionAttributeConverter.sortedSetConverter(IntegerAttributeConverter.create());
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
ListAttributeConverter.Builder<T extends Collection<U>,
U> -
Method Summary
Modifier and TypeMethodDescriptionTheAttributeValueType
that a converter stores and reads values from DynamoDB via theAttributeValue
class.static <T extends Collection<U>,
U>
ListAttributeConverter.Builder<T, U> builder
(EnhancedType<T> collectionType) static <U> ListAttributeConverter
<List<U>> create
(AttributeConverter<U> elementConverter) transformFrom
(T input) Convert the provided Java object into anAttributeValue
.transformTo
(AttributeValue input) Convert the providedAttributeValue
into a Java object.type()
The type supported by this converter.
-
Method Details
-
create
-
builder
public static <T extends Collection<U>,U> ListAttributeConverter.Builder<T,U> builder(EnhancedType<T> collectionType) -
type
Description copied from interface:AttributeConverter
The type supported by this converter.- Specified by:
type
in interfaceAttributeConverter<T extends Collection<?>>
-
attributeValueType
Description copied from interface:AttributeConverter
TheAttributeValueType
that a converter stores and reads values from DynamoDB via theAttributeValue
class.- Specified by:
attributeValueType
in interfaceAttributeConverter<T extends Collection<?>>
-
transformFrom
Description copied from interface:AttributeConverter
Convert the provided Java object into anAttributeValue
. This will raise aRuntimeException
if the conversion fails, or the input is null.Example:
InstantAsStringAttributeConverter converter = InstantAsStringAttributeConverter.create(); assertEquals(converter.transformFrom(Instant.EPOCH), EnhancedAttributeValue.fromString("1970-01-01T00:00:00Z").toAttributeValue());
- Specified by:
transformFrom
in interfaceAttributeConverter<T extends Collection<?>>
-
transformTo
Description copied from interface:AttributeConverter
Convert the providedAttributeValue
into a Java object. This will raise aRuntimeException
if the conversion fails, or the input is null.Example:
InstantAsStringAttributeConverter converter = InstantAsStringAttributeConverter.create(); assertEquals(converter.transformTo(EnhancedAttributeValue.fromString("1970-01-01T00:00:00Z").toAttributeValue()), Instant.EPOCH);
- Specified by:
transformTo
in interfaceAttributeConverter<T extends Collection<?>>
-