@ThreadSafe @Immutable public final class ZonedDateTimeAsStringAttributeConverter extends Object implements AttributeConverter<ZonedDateTime>
ZonedDateTime and AttributeValue.
This stores values in DynamoDB as a string.
Values are stored in a ISO-8601-like format, with the non-offset zone IDs being added at the end of the string in square
brackets. If the zone ID 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, it is better to use OffsetDateTimes (without second-level precision in its
offset) or Instants, assuming the time zone information is not strictly required.
Examples:
Instant.EPOCH.atZone(ZoneId.of("Europe/Paris")) is stored as
an AttributeValue with the String "1970-01-01T01:00+01:00[Europe/Paris]"OffsetDateTime.MIN.toZonedDateTime() is stored as
an AttributeValue with the String "-999999999-01-01T00:00+18:00"OffsetDateTime.MAX.toZonedDateTime() is stored as
an AttributeValue with the String "+999999999-12-31T23:59:59.999999999-18:00"Instant.EPOCH.atZone(ZoneOffset.UTC) is stored as
an AttributeValue with the String "1970-01-01T00:00Z"OffsetDateTime for more details on the serialization format.
This converter can read any values written by itself, InstantAsStringAttributeConverter,
or OffsetDateTimeAsStringAttributeConverter. Values written by
Instant converters are treated as if they are in the UTC time zone.
This serialization is lexicographically orderable when the year is not negative.
This can be created via create().
| Constructor and Description |
|---|
ZonedDateTimeAsStringAttributeConverter() |
| Modifier and Type | Method and Description |
|---|---|
AttributeValueType |
attributeValueType()
The
AttributeValueType that a converter stores and reads values
from DynamoDB via the AttributeValue class. |
static ZonedDateTimeAsStringAttributeConverter |
create() |
AttributeValue |
transformFrom(ZonedDateTime input)
Convert the provided Java object into an
AttributeValue. |
ZonedDateTime |
transformTo(AttributeValue input)
Convert the provided
AttributeValue into a Java object. |
EnhancedType<ZonedDateTime> |
type()
The type supported by this converter.
|
public ZonedDateTimeAsStringAttributeConverter()
public static ZonedDateTimeAsStringAttributeConverter create()
public EnhancedType<ZonedDateTime> type()
AttributeConvertertype in interface AttributeConverter<ZonedDateTime>public AttributeValueType attributeValueType()
AttributeConverterAttributeValueType that a converter stores and reads values
from DynamoDB via the AttributeValue class.attributeValueType in interface AttributeConverter<ZonedDateTime>public AttributeValue transformFrom(ZonedDateTime input)
AttributeConverterAttributeValue. 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<ZonedDateTime>public ZonedDateTime transformTo(AttributeValue input)
AttributeConverterAttributeValue 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<ZonedDateTime>Copyright © 2023. All rights reserved.