@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(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 conversion function needs to be present in the type-converter factory.
To add or override scalar type-conversions,
final DynamoDBMapperConfig.Builder builder = new DynamoDBMapperConfig.Builder(); final DynamoDBTypeConverterFactory.OverrideFactory factory = builder.newTypeConverterFactory(); factory.with(String.class, Locale.class, new DynamoDBTypeConverter<String,Locale>() { public String convert(Locale object) { return object.toLanguageTag(); } public Locale unconvert(final String object) { return Locale.forLanguageTag(object); } }); final DynamoDBMapperConfig config = builder.build();
DynamoDBTypeConverted
,
ScalarAttributeType
Modifier and Type | Required Element and Description |
---|---|
ScalarAttributeType |
type
The scalar attirbute type.
|
public abstract ScalarAttributeType type
ScalarAttributeType
Copyright © 2016. All rights reserved.