Class MapAttributeConverter<T extends Map<?,?>>
- java.lang.Object
-
- software.amazon.awssdk.enhanced.dynamodb.internal.converter.attribute.MapAttributeConverter<T>
-
- All Implemented Interfaces:
AttributeConverter<T>
@ThreadSafe @Immutable public class MapAttributeConverter<T extends Map<?,?>> extends Object implements AttributeConverter<T>
A converter between a specificMap
type andAttributeValue
.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 configuredAttributeConverter
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 configuredAttributeConverter
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:
MapAttributeConverter
-
-
Method Summary
-
-
-
Method Detail
-
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)
-
navigableMapConverter
public static <K,V> MapAttributeConverter<NavigableMap<K,V>> navigableMapConverter(StringConverter<K> keyConverter, AttributeConverter<V> valueConverter)
-
builder
public static <T extends Map<K,V>,K,V> MapAttributeConverter.Builder<T,K,V> builder(EnhancedType<T> mapType)
-
type
public EnhancedType<T> type()
Description copied from interface:AttributeConverter
The type supported by this converter.- Specified by:
type
in interfaceAttributeConverter<T extends Map<?,?>>
-
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 Map<?,?>>
-
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 Map<?,?>>
-
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 Map<?,?>>
-
-