Class DurationAttributeConverter
java.lang.Object
software.amazon.awssdk.enhanced.dynamodb.internal.converter.attribute.DurationAttributeConverter
- All Implemented Interfaces:
AttributeConverter<Duration>
@ThreadSafe
@Immutable
public final class DurationAttributeConverter
extends Object
implements AttributeConverter<Duration>
A converter between
Duration and AttributeValue.
This stores and reads values in DynamoDB as a number, so that they can be sorted numerically as part of a sort key.
Durations are stored in the format "[-]X[.YYYYYYYYY]", where X is the number of seconds in the duration, and Y is the number of nanoseconds in the duration, left padded with zeroes to a length of 9. The Y and decimal point may be excluded for durations that are of whole seconds. The duration may be preceded by a - to indicate a negative duration.
Examples:
Duration.ofDays(1)is stored asItemAttributeValueMapper.fromNumber("86400")Duration.ofSeconds(9)is stored asItemAttributeValueMapper.fromNumber("9")Duration.ofSeconds(-9)is stored asItemAttributeValueMapper.fromNumber("-9")Duration.ofNanos(1_234_567_890)is stored asItemAttributeValueMapper.fromNumber("1.234567890")Duration.ofMillis(1)is stored asItemAttributeValueMapper.fromNumber("0.001000000")Duration.ofNanos(1)is stored asItemAttributeValueMapper.fromNumber("0.000000001")Duration.ofNanos(-1)is stored asItemAttributeValueMapper.fromNumber("-0.000000001")
This can be created via create().
-
Method Summary
Modifier and TypeMethodDescriptionTheAttributeValueTypethat a converter stores and reads values from DynamoDB via theAttributeValueclass.static DurationAttributeConvertercreate()transformFrom(Duration 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
-
create
-
type
Description copied from interface:AttributeConverterThe type supported by this converter.- Specified by:
typein interfaceAttributeConverter<Duration>
-
attributeValueType
Description copied from interface:AttributeConverterTheAttributeValueTypethat a converter stores and reads values from DynamoDB via theAttributeValueclass.- Specified by:
attributeValueTypein interfaceAttributeConverter<Duration>
-
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<Duration>
-
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<Duration>
-