Class SetAttributeConverter<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
Nested ClassesModifier and TypeClassDescriptionstatic final classSetAttributeConverter.Builder<T extends Collection<U>,U> -
Method Summary
Modifier and TypeMethodDescriptionTheAttributeValueTypethat 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) transformFrom(T input) Convert the provided Java object into anAttributeValue.transformTo(AttributeValue input) Convert the providedAttributeValueinto a Java object.type()The type supported by this converter.
-
Method Details
-
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
Description copied from interface:AttributeConverterThe type supported by this converter.- Specified by:
typein interfaceAttributeConverter<T extends Collection<?>>
-
attributeValueType
Description copied from interface:AttributeConverterTheAttributeValueTypethat a converter stores and reads values from DynamoDB via theAttributeValueclass.- Specified by:
attributeValueTypein interfaceAttributeConverter<T extends Collection<?>>
-
transformFrom
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
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<?>>
-