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 specificCollectiontype andEnhancedAttributeValue.This stores values in DynamoDB as a list of attribute values. This uses a configured
AttributeConverterto convert the collection contents to an attribute value.This supports reading a list of attribute values. This uses a configured
AttributeConverterto 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 classSetAttributeConverter.Builder<T extends Collection<U>,U>
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AttributeValueTypeattributeValueType()TheAttributeValueTypethat a converter stores and reads values from DynamoDB via theAttributeValueclass.static <T extends Collection<U>,U>
SetAttributeConverter.Builder<T,U>builder(EnhancedType<T> collectionType)static <U> SetAttributeConverter<Set<U>>setConverter(AttributeConverter<U> elementConverter)AttributeValuetransformFrom(T input)Convert the provided Java object into anAttributeValue.TtransformTo(AttributeValue input)Convert the providedAttributeValueinto 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:AttributeConverterThe type supported by this converter.- Specified by:
typein interfaceAttributeConverter<T extends Collection<?>>
-
attributeValueType
public AttributeValueType attributeValueType()
Description copied from interface:AttributeConverterTheAttributeValueTypethat a converter stores and reads values from DynamoDB via theAttributeValueclass.- Specified by:
attributeValueTypein interfaceAttributeConverter<T extends Collection<?>>
-
transformFrom
public AttributeValue transformFrom(T input)
Description copied from interface:AttributeConverterConvert the provided Java object into anAttributeValue. This will raise aRuntimeExceptionif 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:
transformFromin interfaceAttributeConverter<T extends Collection<?>>
-
transformTo
public T transformTo(AttributeValue input)
Description copied from interface:AttributeConverterConvert the providedAttributeValueinto a Java object. This will raise aRuntimeExceptionif 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:
transformToin interfaceAttributeConverter<T extends Collection<?>>
-
-