Class OffsetDateTimeAsStringAttributeConverter
- java.lang.Object
-
- software.amazon.awssdk.enhanced.dynamodb.internal.converter.attribute.OffsetDateTimeAsStringAttributeConverter
-
- All Implemented Interfaces:
AttributeConverter<OffsetDateTime>
@ThreadSafe @Immutable public final class OffsetDateTimeAsStringAttributeConverter extends Object implements AttributeConverter<OffsetDateTime>
A converter betweenOffsetDateTimeandAttributeValue.This stores values in DynamoDB as a string.
Values are stored in ISO-8601 format, with nanosecond precision. If the offset has seconds then they will also be included, even though this is not part of the ISO-8601 standard. For full ISO-8601 compliance, ensure your
OffsetDateTimes do not have offsets at the precision level of seconds.Examples:
OffsetDateTime.MINis stored as an AttributeValue with the String "-999999999-01-01T00:00+18:00"OffsetDateTime.MAXis stored as an AttributeValue with the String "+999999999-12-31T23:59:59.999999999-18:00"Instant.EPOCH.atOffset(ZoneOffset.UTC).plusSeconds(1)is stored as an AttributeValue with the String "1970-01-01T00:00:01Z"Instant.EPOCH.atOffset(ZoneOffset.UTC).minusSeconds(1)is stored as an AttributeValue with the String "1969-12-31T23:59:59Z"Instant.EPOCH.atOffset(ZoneOffset.UTC).plusMillis(1)is stored as an AttributeValue with the String "1970-01-01T00:00:00.001Z"Instant.EPOCH.atOffset(ZoneOffset.UTC).minusMillis(1)is stored as an AttributeValue with the String "1969-12-31T23:59:59.999Z"Instant.EPOCH.atOffset(ZoneOffset.UTC).plusNanos(1)is stored as an AttributeValue with the String "1970-01-01T00:00:00.000000001Z"Instant.EPOCH.atOffset(ZoneOffset.UTC).minusNanos(1)is stored as an AttributeValue with the String "1969-12-31T23:59:59.999999999Z"
OffsetDateTimefor more details on the serialization format.This converter can read any values written by itself or
InstantAsStringAttributeConverter, and values without a time zone named written byZonedDateTimeAsStringAttributeConverter. Values written byInstantconverters are treated as if they are in the UTC time zone (and an offset of 0 seconds will be returned).This serialization is lexicographically orderable when the year is not negative.
This can be created via
create().
-
-
Constructor Summary
Constructors Constructor Description OffsetDateTimeAsStringAttributeConverter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AttributeValueTypeattributeValueType()TheAttributeValueTypethat a converter stores and reads values from DynamoDB via theAttributeValueclass.static OffsetDateTimeAsStringAttributeConvertercreate()AttributeValuetransformFrom(OffsetDateTime input)Convert the provided Java object into anAttributeValue.OffsetDateTimetransformTo(AttributeValue input)Convert the providedAttributeValueinto a Java object.EnhancedType<OffsetDateTime>type()The type supported by this converter.
-
-
-
Method Detail
-
create
public static OffsetDateTimeAsStringAttributeConverter create()
-
type
public EnhancedType<OffsetDateTime> type()
Description copied from interface:AttributeConverterThe type supported by this converter.- Specified by:
typein interfaceAttributeConverter<OffsetDateTime>
-
attributeValueType
public AttributeValueType attributeValueType()
Description copied from interface:AttributeConverterTheAttributeValueTypethat a converter stores and reads values from DynamoDB via theAttributeValueclass.- Specified by:
attributeValueTypein interfaceAttributeConverter<OffsetDateTime>
-
transformFrom
public AttributeValue transformFrom(OffsetDateTime input)
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<OffsetDateTime>
-
transformTo
public OffsetDateTime transformTo(AttributeValue input)
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<OffsetDateTime>
-
-