@ThreadSafe @Immutable public final class LocalDateTimeAttributeConverter extends Object implements AttributeConverter<LocalDateTime>
LocalDateTime
and AttributeValue
.
This stores and reads values in DynamoDB as a string.
Values are stored with nanosecond precision.
LocalDateTimes are stored in the official LocalDateTime
format "[-]YYYY-MM-DDTHH:II:SS[.NNNNNNNNN]", where:
Year.MIN_VALUE
and Year.MAX_VALUE
(prefixed with - if it is negative)LocalDateTime
for more details on the serialization format.
This is format-compatible with the LocalDateAttributeConverter
, allowing values stored as LocalDate
to be
retrieved as LocalDateTime
s. The time associated with a value stored as a LocalDate
is the
beginning of the day (midnight).
This serialization is lexicographically orderable when the year is not negative.
Examples:LocalDateTime.of(1988, 5, 21, 0, 0, 0)
is stored as
an AttributeValue with the String "1988-05-21T00:00"LocalDateTime.of(-1988, 5, 21, 0, 0, 0)
is stored as
an AttributeValue with the String "-1988-05-21T00:00"LocalDateTime.of(1988, 5, 21, 0, 0, 0).plusSeconds(1)
is stored as
an AttributeValue with the String "1988-05-21T00:00:01"LocalDateTime.of(1988, 5, 21, 0, 0, 0).minusSeconds(1)
is stored as
an AttributeValue with the String "1988-05-20T23:59:59"LocalDateTime.of(1988, 5, 21, 0, 0, 0).plusNanos(1)
is stored as
an AttributeValue with the String "1988-05-21T00:00:00.0000000001"LocalDateTime.of(1988, 5, 21, 0, 0, 0).minusNanos(1)
is stored as
an AttributeValue with the String "1988-05-20T23:59:59.999999999"
This can be created via create()
.
Constructor and Description |
---|
LocalDateTimeAttributeConverter() |
Modifier and Type | Method and Description |
---|---|
AttributeValueType |
attributeValueType()
The
AttributeValueType that a converter stores and reads values
from DynamoDB via the AttributeValue class. |
static LocalDateTimeAttributeConverter |
create() |
AttributeValue |
transformFrom(LocalDateTime input)
Convert the provided Java object into an
AttributeValue . |
LocalDateTime |
transformTo(AttributeValue input)
Convert the provided
AttributeValue into a Java object. |
EnhancedType<LocalDateTime> |
type()
The type supported by this converter.
|
public static LocalDateTimeAttributeConverter create()
public EnhancedType<LocalDateTime> type()
AttributeConverter
type
in interface AttributeConverter<LocalDateTime>
public AttributeValueType attributeValueType()
AttributeConverter
AttributeValueType
that a converter stores and reads values
from DynamoDB via the AttributeValue
class.attributeValueType
in interface AttributeConverter<LocalDateTime>
public AttributeValue transformFrom(LocalDateTime input)
AttributeConverter
AttributeValue
. This will raise a RuntimeException
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());
transformFrom
in interface AttributeConverter<LocalDateTime>
public LocalDateTime transformTo(AttributeValue input)
AttributeConverter
AttributeValue
into a Java object. This will raise a RuntimeException
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);
transformTo
in interface AttributeConverter<LocalDateTime>
Copyright © 2021. All rights reserved.