@Retention(value=RUNTIME) @Target(value={FIELD,METHOD}) public @interface DynamoDBScalarAttribute
A minimal example using getter annotations,
@DynamoDBTable(tableName="TestTable") public class TestClass { private UUID key; private Locale locale; @DynamoDBHashKey @DynamoDBScalarAttribute(type=ScalarAttributeType.B) public UUID getKey() { return this.key; } public void setKey(UUID key) { this.key = key; } @DynamoDBScalarAttribute(attributeName="userLocale", type=ScalarAttributeType.S) public Locale getLocale() { return this.locale; } public void setLocale(Locale locale) { this.locale = locale; } }
Here we are overriding the standard UUID
type conversion
to ByteBuffer
rather than the default String
.
Please note, the DynamoDBTypeConverter
for the source and target
need to be present in the type-converter factory. To add or override one or
more, scalar type-conversions, using the standard conversion factory as the
default/fallback,
return DynamoDBMapperConfig.builder() .withTypeConverterFactory(DynamoDBTypeConverterFactory.standard().override() .with(String.class, Locale.class, new StringToLocaleConverter()) .with(String.class, DateTime.class, new StringToDateTimeConverter()) .with(String.class, LocalDateTime.class, new StringToLocalDateTimeConverter()) .build()) .build();
com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig#getTypeConverterFactory
,
DynamoDBTypeConverterFactory.standard()
,
ScalarAttributeType
Modifier and Type | Required Element and Description |
---|---|
ScalarAttributeType |
type
The scalar attirbute type.
|
Modifier and Type | Optional Element and Description |
---|---|
String |
attributeName
Optional parameter when the name of the attribute as stored in DynamoDB
should differ from the name used by the getter / setter.
|
public abstract ScalarAttributeType type
ScalarAttributeType
public abstract String attributeName
Copyright © 2016. All rights reserved.