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
-
Method Summary
Modifier and TypeMethodDescriptionTheAttributeValueType
that a converter stores and reads values from DynamoDB via theAttributeValue
class.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 providedAttributeValue
into 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:AttributeConverter
The type supported by this converter.- Specified by:
type
in interfaceAttributeConverter<T extends Map<?,
?>>
-
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 Map<?,
?>>
-
transformFrom
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 Map<?,
?>>
-
transformTo
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 Map<?,
?>>
-