@ThreadSafe @Immutable public final class BigDecimalAttributeConverter extends Object implements AttributeConverter<BigDecimal>
BigDecimal
and AttributeValue
.
This stores values in DynamoDB as a number.
This supports perfect precision with the full range of numbers that can be stored in DynamoDB. For less precision or
smaller values, consider using FloatAttributeConverter
or DoubleAttributeConverter
.
If values are known to be whole numbers, it is recommended to use a perfect-precision whole number representation like those
provided by ShortAttributeConverter
, IntegerAttributeConverter
or BigIntegerAttributeConverter
.
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 BigDecimalAttributeConverter |
create() |
AttributeValue |
transformFrom(BigDecimal input)
Convert the provided Java object into an
AttributeValue . |
BigDecimal |
transformTo(AttributeValue input)
Convert the provided
AttributeValue into a Java object. |
EnhancedType<BigDecimal> |
type()
The type supported by this converter.
|
public static BigDecimalAttributeConverter create()
public EnhancedType<BigDecimal> type()
AttributeConverter
type
in interface AttributeConverter<BigDecimal>
public AttributeValueType attributeValueType()
AttributeConverter
AttributeValueType
that a converter stores and reads values
from DynamoDB via the AttributeValue
class.attributeValueType
in interface AttributeConverter<BigDecimal>
public AttributeValue transformFrom(BigDecimal 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<BigDecimal>
public BigDecimal 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<BigDecimal>
Copyright © 2021. All rights reserved.