@Retention(value=RUNTIME) @Target(value={TYPE,FIELD,METHOD,ANNOTATION_TYPE}) public @interface DynamoDBTypeConverted
May be annotated on a user-defined annotation to pass additional
properties to the DynamoDBTypeConverter
.
@CurrencyFormat(separator=" ") //<- user-defined annotation public Currency getCurrency()
Where,
public class Currency { private Double amount; private String unit; public Double getAmount() { return amount; } public void setAmount(Double amount) { this.amount = amount; } public String getUnit() { return unit; } public void setUnit(String unit) { this.unit = unit; } }
And user-defined annotation,
@Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @DynamoDBTypeConverted(converter=CurrencyFormat.Converter.class) public @interface CurrencyFormat { String separator() default " "; public static class Converter implements DynamoDBTypeConverter<String,Currency> { private final String separator; public Converter(final Class<Currency> targetType, final CurrencyFormat annotation) { this.separator = annotation.separator(); } public Converter() { this.separator = "|"; } @Override public String convert(final Currency o) { return String.valueOf(o.getAmount()) + separator + o.getUnit(); } @Override public Currency unconvert(final String o) { final String[] strings = o.split(separator); final Currency currency = new Currency(); currency.setAmount(Double.valueOf(strings[0])); currency.setUnit(strings[1]); return currency; } } }
Alternately, the property/field may be annotated directly (which
requires the converter to provide a default constructor or a constructor
with only the targetType
),
@DynamoDBTypeConverted(converter=CurrencyFormat.Converter.class) public Currency getCurrency() { return currency; }
All converters are null-safe, a null
value will never be passed
to DynamoDBTypeConverter.convert(T)
or DynamoDBTypeConverter.unconvert(S)
.
Precedence for selecting a type-converter first goes to getter annotations, then field, then finally type.
May be used in combination with DynamoDBTyped
to specify the
attribute type binding.
Compatible with DynamoDBAutoGeneratedTimestamp
May be used as a meta-annotation.
Modifier and Type | Required Element and Description |
---|---|
Class<? extends DynamoDBTypeConverter> |
converter
The class of the converter for this property.
|
public abstract Class<? extends DynamoDBTypeConverter> converter
Copyright © 2013 Amazon Web Services, Inc. All Rights Reserved.