Class MapAttributeConverter<T extends Map<?,?>>
- All Implemented Interfaces:
AttributeConverter<T>
Map type and AttributeValue.
This stores values in DynamoDB as a map from string to attribute value. This uses a configured StringAttributeConverter
to convert the map keys to a string, and a configured AttributeConverter to convert the map values to an attribute
value.
This supports reading maps from DynamoDB. This uses a configured StringAttributeConverter to convert the map keys, and
a configured AttributeConverter to convert the map values.
A builder is exposed to allow defining how the map, key and value types are created and converted:
AttributeConverter<Map<MonthDay, String>> mapConverter =
MapAttributeConverter.builder(EnhancedType.mapOf(Integer.class, String.class))
.mapConstructor(HashMap::new)
.keyConverter(MonthDayStringConverter.create())
.valueConverter(StringAttributeConverter.create())
.build();
For frequently-used types, static methods are exposed to reduce the amount of boilerplate involved in creation:
AttributeConverter<Map<MonthDay, String>> mapConverter =
MapAttributeConverter.mapConverter(MonthDayStringConverter.create(),
StringAttributeConverter.create());
AttributeConverter<SortedMap<MonthDay, String>> sortedMapConverter =
MapAttributeConverter.sortedMapConverter(MonthDayStringConverter.create(),
StringAttributeConverter.create());
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionTheAttributeValueTypethat a converter stores and reads values from DynamoDB via theAttributeValueclass.static <T extends Map<K,V>, K, V>
MapAttributeConverter.Builder<T, K, V> builder(EnhancedType<T> mapType) static <K,V> MapAttributeConverter <ConcurrentMap<K, V>> concurrentMapConverter(StringConverter<K> keyConverter, AttributeConverter<V> valueConverter) static <K,V> MapAttributeConverter <Map<K, V>> mapConverter(StringConverter<K> keyConverter, AttributeConverter<V> valueConverter) static <K,V> MapAttributeConverter <NavigableMap<K, V>> navigableMapConverter(StringConverter<K> keyConverter, AttributeConverter<V> valueConverter) static <K,V> MapAttributeConverter <SortedMap<K, V>> sortedMapConverter(StringConverter<K> keyConverter, AttributeConverter<V> valueConverter) 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
-
mapConverter
public static <K,V> MapAttributeConverter<Map<K,V>> mapConverter(StringConverter<K> keyConverter, AttributeConverter<V> valueConverter) -
concurrentMapConverter
public static <K,V> MapAttributeConverter<ConcurrentMap<K,V>> concurrentMapConverter(StringConverter<K> keyConverter, AttributeConverter<V> valueConverter) -
sortedMapConverter
public static <K,V> MapAttributeConverter<SortedMap<K,V>> sortedMapConverter(StringConverter<K> keyConverter, AttributeConverter<V> valueConverter) -
builder
public static <T extends Map<K,V>, MapAttributeConverter.Builder<T,K, V> K, builderV> (EnhancedType<T> mapType) -
type
Description copied from interface:AttributeConverterThe type supported by this converter.- Specified by:
typein interfaceAttributeConverter<T extends Map<?,?>>
-
attributeValueType
Description copied from interface:AttributeConverterTheAttributeValueTypethat a converter stores and reads values from DynamoDB via theAttributeValueclass.- Specified by:
attributeValueTypein interfaceAttributeConverter<T extends Map<?,?>>
-
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 Map<?,?>>
-
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 Map<?,?>>
-