@ThreadSafe @Immutable public class SetAttributeConverter<T extends Collection<?>> extends Object implements 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());
MapAttributeConverter
Modifier and Type | Class and Description |
---|---|
static class |
SetAttributeConverter.Builder<T extends Collection<U>,U> |
Modifier and Type | Method and Description |
---|---|
AttributeValueType |
attributeValueType()
The
AttributeValueType that a converter stores and reads values
from DynamoDB via the AttributeValue class. |
static <T extends Collection<U>,U> |
builder(EnhancedType<T> collectionType) |
static <U> SetAttributeConverter<Set<U>> |
setConverter(AttributeConverter<U> elementConverter) |
AttributeValue |
transformFrom(T input)
Convert the provided Java object into an
AttributeValue . |
T |
transformTo(AttributeValue input)
Convert the provided
AttributeValue into a Java object. |
EnhancedType<T> |
type()
The type supported by this converter.
|
public static <U> SetAttributeConverter<Set<U>> setConverter(AttributeConverter<U> elementConverter)
public static <T extends Collection<U>,U> SetAttributeConverter.Builder<T,U> builder(EnhancedType<T> collectionType)
public EnhancedType<T> type()
AttributeConverter
type
in interface AttributeConverter<T extends Collection<?>>
public AttributeValueType attributeValueType()
AttributeConverter
AttributeValueType
that a converter stores and reads values
from DynamoDB via the AttributeValue
class.attributeValueType
in interface AttributeConverter<T extends Collection<?>>
public AttributeValue transformFrom(T input)
AttributeConverter
AttributeValue
. This will raise a RuntimeException
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());
transformFrom
in interface AttributeConverter<T extends Collection<?>>
public T transformTo(AttributeValue input)
AttributeConverter
AttributeValue
into a Java object. This will raise a RuntimeException
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);
transformTo
in interface AttributeConverter<T extends Collection<?>>
Copyright © 2021. All rights reserved.