@ThreadSafe @Immutable public final class InstantAsIntegerAttributeConverter extends Object implements AttributeConverter<Instant>
Instant and AttributeValue.
This stores values in DynamoDB as a number, so that they can be sorted numerically as part of a sort key.
Instants are stored in the format "[-]X[.Y]", where X is the number of seconds past the epoch of 1970-01-01T00:00:00Z in this instant, and Y is the fraction of seconds, up to the nanosecond precision (Y is at most 9 characters long).
Examples:
Instant.EPOCH.plusSeconds(1) is stored as ItemAttributeValueMapper.fromNumber("1")Instant.EPOCH.minusSeconds(1) is stored as ItemAttributeValueMapper.fromNumber("-1")Instant.EPOCH.plusMillis(1) is stored as ItemAttributeValueMapper.fromNumber("0.001")Instant.EPOCH.minusMillis(1) is stored as ItemAttributeValueMapper.fromNumber("-0.001")Instant.EPOCH.plusNanos(1) is stored as ItemAttributeValueMapper.fromNumber("0.000000001")Instant.EPOCH.minusNanos(1) is stored as ItemAttributeValueMapper.fromNumber("-0.000000001")
This converter can read any values written by itself, InstantAsStringAttributeConverter,
OffsetDateTimeAsStringAttributeConverter or ZonedDateTimeAsStringAttributeConverter. Offset and zoned times
will be automatically converted to the equivalent Instant based on the time zone information in the record (e.g.
ItemAttributeValueMapper.fromString("1970-01-01T00:00:00+01:00") will be converted to
Instant.EPOCH.minus(1, ChronoUnit.HOURS)).
This can be created via create().
| Modifier and Type | Method and Description |
|---|---|
AttributeValueType |
attributeValueType()
The
AttributeValueType that a converter stores and reads values
from DynamoDB via the AttributeValue class. |
static InstantAsIntegerAttributeConverter |
create() |
AttributeValue |
transformFrom(Instant input)
Convert the provided Java object into an
AttributeValue. |
Instant |
transformTo(AttributeValue input)
Convert the provided
AttributeValue into a Java object. |
EnhancedType<Instant> |
type()
The type supported by this converter.
|
public static InstantAsIntegerAttributeConverter create()
public EnhancedType<Instant> type()
AttributeConvertertype in interface AttributeConverter<Instant>public AttributeValueType attributeValueType()
AttributeConverterAttributeValueType that a converter stores and reads values
from DynamoDB via the AttributeValue class.attributeValueType in interface AttributeConverter<Instant>public AttributeValue transformFrom(Instant 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<Instant>public Instant transformTo(AttributeValue input)
AttributeConverterAttributeValue 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<Instant>Copyright © 2020. All rights reserved.