@ThreadSafe @Immutable public final class LocalDateTimeAttributeConverter extends Object implements AttributeConverter<LocalDateTime>
LocalDateTime
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.
LocalDateTimes are stored in the format "[-]YYYYMMDDHHIISS[.NNNNNNNNN]", where:
Year.MIN_VALUE
and Year.MAX_VALUE
(prefixed with - if it is negative)
This is format-compatible with the LocalDateAttributeConverter
, allowing values stored as LocalDate
to be
retrieved as LocalDateTime
s and vice-versa. The time associated with a value stored as a LocalDate
is the
beginning of the day (midnight).
Examples:
LocalDateTime.of(1988, 5, 21, 0, 0, 0)
is stored as
ItemAttributeValueMapper.fromNumber("19880521000000")
LocalDateTime.of(-1988, 5, 21, 0, 0, 0)
is stored as
ItemAttributeValueMapper.fromNumber("-19880521000000")
LocalDateTime.of(1988, 5, 21, 0, 0, 0).plusSeconds(1)
is stored as
ItemAttributeValueMapper.fromNumber("19880521000001")
LocalDateTime.of(1988, 5, 21, 0, 0, 0).minusSeconds(1)
is stored as
ItemAttributeValueMapper.fromNumber("19880520235959")
LocalDateTime.of(1988, 5, 21, 0, 0, 0).plusNanos(1)
is stored as
ItemAttributeValueMapper.fromNumber("19880521000000.0000000001")
LocalDateTime.of(1988, 5, 21, 0, 0, 0).minusNanos(1)
is stored as
ItemAttributeValueMapper.fromNumber("19880520235959.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: {@code InstantAsStringAttributeConverter converter = InstantAsStringAttributeConverter.create(); assertEquals(converter.transformTo(EnhancedAttributeValue.fromString("1970-01-01T00:00:00Z").toAttributeValue()), Instant.EPOCH);
transformTo
in interface AttributeConverter<LocalDateTime>
Copyright © 2020. All rights reserved.