Class SetAttributeConverter<T extends Collection<?>>
- java.lang.Object
-
- software.amazon.awssdk.enhanced.dynamodb.internal.converter.attribute.SetAttributeConverter<T>
-
- All Implemented Interfaces:
AttributeConverter<T>
@ThreadSafe @Immutable public class SetAttributeConverter<T extends Collection<?>> extends Object implements AttributeConverter<T>
A converter between a specificCollection
type andEnhancedAttributeValue
.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:
MapAttributeConverter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SetAttributeConverter.Builder<T extends Collection<U>,U>
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AttributeValueType
attributeValueType()
TheAttributeValueType
that a converter stores and reads values from DynamoDB via theAttributeValue
class.static <T extends Collection<U>,U>
SetAttributeConverter.Builder<T,U>builder(EnhancedType<T> collectionType)
static <U> SetAttributeConverter<Set<U>>
setConverter(AttributeConverter<U> elementConverter)
AttributeValue
transformFrom(T input)
Convert the provided Java object into anAttributeValue
.T
transformTo(AttributeValue input)
Convert the providedAttributeValue
into a Java object.EnhancedType<T>
type()
The type supported by this converter.
-
-
-
Method Detail
-
setConverter
public static <U> SetAttributeConverter<Set<U>> setConverter(AttributeConverter<U> elementConverter)
-
builder
public static <T extends Collection<U>,U> SetAttributeConverter.Builder<T,U> builder(EnhancedType<T> collectionType)
-
type
public EnhancedType<T> type()
Description copied from interface:AttributeConverter
The type supported by this converter.- Specified by:
type
in interfaceAttributeConverter<T extends Collection<?>>
-
attributeValueType
public AttributeValueType 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
public AttributeValue transformFrom(T input)
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
public T transformTo(AttributeValue input)
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<?>>
-
-