All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTyped Maven / Gradle / Ivy

Go to download

The AWS Java SDK for Amazon DynamoDB module holds the client classes that are used for communicating with Amazon DynamoDB Service

There is a newer version: 1.12.765
Show newest version
/*
 * Copyright 2016-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *    http://aws.amazon.com/apache2.0
 *
 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
 * OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and
 * limitations under the License.
 */
package com.amazonaws.services.dynamodbv2.datamodeling;

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperFieldModel.DynamoDBAttributeType;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * Annotation to override the standard attribute type binding.
 *
 * 
 * @DynamoDBTyped(DynamoDBAttributeType.S)
 * public MyObject getMyObject()
 * 
*

Standard Types

*

Standard types do not require the annotation if applying the default * attribute binding for that type.

*

String/{@code S} types,

*
    *
  • {@link java.lang.Character}/{@code char}
  • *
  • {@link java.lang.String}
  • *
  • {@link java.net.URL}
  • *
  • {@link java.net.URI}
  • *
  • {@link java.util.Calendar}
  • *
  • {@link java.util.Currency}
  • *
  • {@link java.util.Date}
  • *
  • {@link java.util.Locale}
  • *
  • {@link java.util.TimeZone}
  • *
  • {@link java.util.UUID}
  • *
  • {@link S3Link}
  • *
*

Number/{@code N} types,

*
    *
  • {@link java.math.BigDecimal}
  • *
  • {@link java.math.BigInteger}
  • *
  • {@link java.lang.Boolean}/{@code boolean}
  • *
  • {@link java.lang.Byte}/{@code byte}
  • *
  • {@link java.lang.Double}/{@code double}
  • *
  • {@link java.lang.Float}/{@code float}
  • *
  • {@link java.lang.Integer}/{@code int}
  • *
  • {@link java.lang.Long}/{@code long}
  • *
  • {@link java.lang.Short}/{@code short}
  • *
*

Binary/{@code B} types,

*
    *
  • {@link java.nio.ByteBuffer}
  • *
  • {@code byte[]}
  • *
* *

{@link DynamoDBTypeConverter}

*

A custom type-converter maybe applied to any attribute, either by * annotation or by overriding the standard type-converter factory.

*
 * DynamoDBMapperConfig config = DynamoDBMapperConfig.builder()
 *     .withTypeConverterFactory(DynamoDBTypeConverterFactory.standard().override()
 *         .with(String.class, MyObject.class, new StringToMyObjectConverter())
 *         .build())
 *     .build();
 * 
*

If the converter being applied is already a supported data type and * the conversion is of the same attribute type, for instance, * {@link java.util.Date} to {@link String} to {@code S}, * the annotation may be omited. The annotation is require for all non-standard * types or if the attribute type binding is being overriden.

* *

{@link com.amazonaws.services.dynamodbv2.model.AttributeValue}

*

Direct native conversion is supported by default in all schemas. * If the attribute is a primary or index key, it must specify either * {@code B}, {@code N}, or {@code S}, otherwise, it may be omited.

* *

{@link Boolean} to {@code BOOL}

*

The standard V2 conversion schema will by default serialize booleans * natively using the DynamoDB {@code BOOL} type.

*
 * @DynamoDBTyped(DynamoDBAttributeType.BOOL)
 * public boolean isTesting()
 * 
* *

{@link Boolean} to {@code N}

*

The standard V1 and V2 compatible conversion schemas will by default * serialize booleans using the DynamoDB {@code N} type, with a value of '1' * representing 'true' and a value of '0' representing 'false'.

*
 * @DynamoDBTyped(DynamoDBAttributeType.N)
 * public boolean isTesting()
 * 
* *

{@link Enum} to {@code S}

*

The {@code enum} type is only supported by override or custom converter. * There are some risks in distributed systems when using enumerations as * attributes instead of simply using a String. When adding new values to the * enumeration, the enum only changes must deployed before the enumeration * value can be persisted. This will ensure that all systems have the correct * code to map it from the item record in DynamoDB to your objects.

*
 * public enum Status { OPEN, PENDING, CLOSED };
 *
 * @DynamoDBTyped(DynamoDBAttributeType.S)
 * public Status getStatus()
 * 
* *

{@link UUID} to {@code B}

*

The {@code UUID} type will serialize to {@link String}/{@code S} by * default in all conversion schemas. The schemas do support serializing to * {@link ByteBuffer}/{@code B} by override.

*
 * @DynamoDBTyped(DynamoDBAttributeType.B)
 * public UUID getKey()
 * 
* *

{@link Set} to {@code L}

*

The standard V1 and V2 compatible conversion schemas do not by default * support non-scalar {@code Set} types. They are supported in V2. In * non-supported schemas, the {@link List}/{@code L} override may be applied * to any {@code Set} type.

*
 * @DynamoDBTyped(DynamoDBAttributeType.L)
 * public Set<MyObject> getMyObjects()
 * 
* *

{@link Object} to {@code M}

*

Also supported as {@link DynamoDBDocument}.

*
 * @DynamoDBTyped(DynamoDBAttributeType.M)
 * public MyObject getMyObject()
 * 
* *

May be combined with {@link DynamoDBTypeConverted}.

* *

May be used as a meta-annotation.

* * @see com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTypeConverted * @see com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTypeConverterFactory */ @DynamoDB @Inherited @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE}) public @interface DynamoDBTyped { /** * Use when the type of the attribute as stored in DynamoDB should differ * from the standard type assigned by DynamoDBMapper. */ DynamoDBAttributeType value() default DynamoDBAttributeType.NULL; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy