Class EnhancedAttributeValue
- java.lang.Object
-
- software.amazon.awssdk.enhanced.dynamodb.internal.converter.attribute.EnhancedAttributeValue
-
@ThreadSafe @Immutable public final class EnhancedAttributeValue extends Object
A simpler, and more user-friendly version of the generatedAttributeValue
.This is a union type of the types exposed by DynamoDB, exactly as they're exposed by DynamoDB.
An instance of
EnhancedAttributeValue
represents exactly one DynamoDB type, like String (s), Number (n) or Bytes (b). This type can be determined with thetype()
method or theis*
methods likeisString()
orisNumber()
. Once the type is known, the value can be extracted withas*
methods likeasString()
orasNumber()
.When converting an
EnhancedAttributeValue
into a concrete Java type, it can be tedious to use thetype()
oris*
methods. For this reason, aconvert(TypeConvertingVisitor)
method is provided that exposes a polymorphic way of converting a value into another type.An instance of
EnhancedAttributeValue
is created with thefrom*
methods, likefromString(String)
orfromNumber(String)
.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Boolean
asBoolean()
Retrieve this value as a boolean.SdkBytes
asBytes()
Retrieve this value as bytes.List<AttributeValue>
asListOfAttributeValues()
Retrieve this value as a list of attribute values.Map<String,AttributeValue>
asMap()
Retrieve this value as a map.String
asNumber()
Retrieve this value as a number.List<SdkBytes>
asSetOfBytes()
Retrieve this value as a set of bytes.List<String>
asSetOfNumbers()
Retrieve this value as a set of numbers.List<String>
asSetOfStrings()
Retrieve this value as a set of strings.String
asString()
Retrieve this value as a string.<T> T
convert(TypeConvertingVisitor<T> convertingVisitor)
Apply the provided visitor to this item attribute value, converting it into a specific type.boolean
equals(Object o)
static EnhancedAttributeValue
fromAttributeValue(AttributeValue attributeValue)
Create anEnhancedAttributeValue
from a generatedAttributeValue
.static EnhancedAttributeValue
fromBoolean(Boolean booleanValue)
Create anEnhancedAttributeValue
for a boolean (bool) DynamoDB type.static EnhancedAttributeValue
fromBytes(SdkBytes bytesValue)
Create anEnhancedAttributeValue
for a bytes (b) DynamoDB type.static EnhancedAttributeValue
fromListOfAttributeValues(List<AttributeValue> listOfAttributeValuesValue)
Create anEnhancedAttributeValue
for a list-of-attributes (l) DynamoDB type.static EnhancedAttributeValue
fromListOfAttributeValues(AttributeValue... listOfAttributeValuesValue)
Create anEnhancedAttributeValue
for a list-of-attributes (l) DynamoDB type.static EnhancedAttributeValue
fromMap(Map<String,AttributeValue> mapValue)
Create anEnhancedAttributeValue
for a map (m) DynamoDB type.static EnhancedAttributeValue
fromNumber(String numberValue)
Create anEnhancedAttributeValue
for a number (n) DynamoDB type.static EnhancedAttributeValue
fromSetOfBytes(Collection<SdkBytes> setOfBytesValue)
Create anEnhancedAttributeValue
for a set-of-bytes (bs) DynamoDB type.static EnhancedAttributeValue
fromSetOfBytes(List<SdkBytes> setOfBytesValue)
Create anEnhancedAttributeValue
for a set-of-bytes (bs) DynamoDB type.static EnhancedAttributeValue
fromSetOfBytes(SdkBytes... setOfBytesValue)
Create anEnhancedAttributeValue
for a set-of-bytes (bs) DynamoDB type.static EnhancedAttributeValue
fromSetOfNumbers(String... setOfNumbersValue)
Create anEnhancedAttributeValue
for a set-of-numbers (ns) DynamoDB type.static EnhancedAttributeValue
fromSetOfNumbers(Collection<String> setOfNumbersValue)
Create anEnhancedAttributeValue
for a set-of-numbers (ns) DynamoDB type.static EnhancedAttributeValue
fromSetOfNumbers(List<String> setOfNumbersValue)
Create anEnhancedAttributeValue
for a set-of-numbers (ns) DynamoDB type.static EnhancedAttributeValue
fromSetOfStrings(String... setOfStringsValue)
Create anEnhancedAttributeValue
for a set-of-strings (ss) DynamoDB type.static EnhancedAttributeValue
fromSetOfStrings(Collection<String> setOfStringsValue)
Create anEnhancedAttributeValue
for a set-of-strings (ss) DynamoDB type.static EnhancedAttributeValue
fromSetOfStrings(List<String> setOfStringsValue)
Create anEnhancedAttributeValue
for a set-of-strings (ss) DynamoDB type.static EnhancedAttributeValue
fromString(String stringValue)
Create anEnhancedAttributeValue
for a string (s) DynamoDB type.int
hashCode()
boolean
isBoolean()
Returns true if the underlying DynamoDB type of this value is a Boolean (bool).boolean
isBytes()
Returns true if the underlying DynamoDB type of this value is Bytes (b).boolean
isListOfAttributeValues()
Returns true if the underlying DynamoDB type of this value is a List of AttributeValues (l).boolean
isMap()
Returns true if the underlying DynamoDB type of this value is a Map (m).boolean
isNull()
Returns true if the underlying DynamoDB type of this value is Null (null).boolean
isNumber()
Returns true if the underlying DynamoDB type of this value is a Number (n).boolean
isSetOfBytes()
Returns true if the underlying DynamoDB type of this value is a Set of Bytes (bs).boolean
isSetOfNumbers()
Returns true if the underlying DynamoDB type of this value is a Set of Numbers (ns).boolean
isSetOfStrings()
Returns true if the underlying DynamoDB type of this value is a Set of Strings (ss).boolean
isString()
Returns true if the underlying DynamoDB type of this value is a String (s).static EnhancedAttributeValue
nullValue()
Create anEnhancedAttributeValue
for the null DynamoDB type.AttributeValue
toAttributeValue()
Convert thisEnhancedAttributeValue
into a generatedAttributeValue
.Map<String,AttributeValue>
toAttributeValueMap()
Convert thisEnhancedAttributeValue
into a generatedMap<String, AttributeValue>
.String
toString()
AttributeValueType
type()
Retrieve the underlying DynamoDB type of this value, such as String (s) or Number (n).
-
-
-
Method Detail
-
nullValue
public static EnhancedAttributeValue nullValue()
Create anEnhancedAttributeValue
for the null DynamoDB type.Equivalent to:
EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().nul(true).build())
This call should never fail with an
Exception
.
-
fromMap
public static EnhancedAttributeValue fromMap(Map<String,AttributeValue> mapValue)
Create anEnhancedAttributeValue
for a map (m) DynamoDB type.Equivalent to:
EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().m(...).build())
This call will fail with a
RuntimeException
if the provided map is null or has null keys.
-
fromString
public static EnhancedAttributeValue fromString(String stringValue)
Create anEnhancedAttributeValue
for a string (s) DynamoDB type.Equivalent to:
EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().s(...).build())
This call will fail with a
RuntimeException
if the provided value is null. UsenullValue()
for null values.
-
fromNumber
public static EnhancedAttributeValue fromNumber(String numberValue)
Create anEnhancedAttributeValue
for a number (n) DynamoDB type.This is a String, because it matches the underlying DynamoDB representation.
Equivalent to:
EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().n(...).build())
This call will fail with a
RuntimeException
if the provided value is null. UsenullValue()
for null values.
-
fromBytes
public static EnhancedAttributeValue fromBytes(SdkBytes bytesValue)
Create anEnhancedAttributeValue
for a bytes (b) DynamoDB type.Equivalent to:
EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().b(...).build())
This call will fail with a
RuntimeException
if the provided value is null. UsenullValue()
for null values.
-
fromBoolean
public static EnhancedAttributeValue fromBoolean(Boolean booleanValue)
Create anEnhancedAttributeValue
for a boolean (bool) DynamoDB type.Equivalent to:
EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().bool(...).build())
This call will fail with a
RuntimeException
if the provided value is null. UsenullValue()
for null values.
-
fromSetOfStrings
public static EnhancedAttributeValue fromSetOfStrings(String... setOfStringsValue)
Create anEnhancedAttributeValue
for a set-of-strings (ss) DynamoDB type.Equivalent to:
EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().ss(...).build())
This call will fail with a
RuntimeException
if the provided value is null or contains a null value. UsefromListOfAttributeValues(List)
for null values. This will not validate that there are no duplicate values.
-
fromSetOfStrings
public static EnhancedAttributeValue fromSetOfStrings(Collection<String> setOfStringsValue)
Create anEnhancedAttributeValue
for a set-of-strings (ss) DynamoDB type.Equivalent to:
EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().ss(...).build())
This call will fail with a
RuntimeException
if the provided value is null or contains a null value. UsefromListOfAttributeValues(List)
for null values. This will not validate that there are no duplicate values.
-
fromSetOfStrings
public static EnhancedAttributeValue fromSetOfStrings(List<String> setOfStringsValue)
Create anEnhancedAttributeValue
for a set-of-strings (ss) DynamoDB type.Equivalent to:
EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().ss(...).build())
This call will fail with a
RuntimeException
if the provided value is null or contains a null value. UsefromListOfAttributeValues(List)
for null values. This will not validate that there are no duplicate values.
-
fromSetOfNumbers
public static EnhancedAttributeValue fromSetOfNumbers(String... setOfNumbersValue)
Create anEnhancedAttributeValue
for a set-of-numbers (ns) DynamoDB type.Equivalent to:
EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().ns(...).build())
This call will fail with a
RuntimeException
if the provided value is null or contains a null value. UsefromListOfAttributeValues(List)
for null values. This will not validate that there are no duplicate values.
-
fromSetOfNumbers
public static EnhancedAttributeValue fromSetOfNumbers(Collection<String> setOfNumbersValue)
Create anEnhancedAttributeValue
for a set-of-numbers (ns) DynamoDB type.Equivalent to:
EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().ns(...).build())
This call will fail with a
RuntimeException
if the provided value is null or contains a null value. UsefromListOfAttributeValues(List)
for null values. This will not validate that there are no duplicate values.
-
fromSetOfNumbers
public static EnhancedAttributeValue fromSetOfNumbers(List<String> setOfNumbersValue)
Create anEnhancedAttributeValue
for a set-of-numbers (ns) DynamoDB type.Equivalent to:
EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().ns(...).build())
This call will fail with a
RuntimeException
if the provided value is null or contains a null value. UsefromListOfAttributeValues(List)
for null values. This will not validate that there are no duplicate values.
-
fromSetOfBytes
public static EnhancedAttributeValue fromSetOfBytes(Collection<SdkBytes> setOfBytesValue)
Create anEnhancedAttributeValue
for a set-of-bytes (bs) DynamoDB type.Equivalent to:
EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().bs(...).build())
This call will fail with a
RuntimeException
if the provided value is null or contains a null value. UsefromListOfAttributeValues(List)
for null values. This will not validate that there are no duplicate values.
-
fromSetOfBytes
public static EnhancedAttributeValue fromSetOfBytes(SdkBytes... setOfBytesValue)
Create anEnhancedAttributeValue
for a set-of-bytes (bs) DynamoDB type.Equivalent to:
EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().bs(...).build())
This call will fail with a
RuntimeException
if the provided value is null or contains a null value. UsefromListOfAttributeValues(List)
for null values. This will not validate that there are no duplicate values.
-
fromSetOfBytes
public static EnhancedAttributeValue fromSetOfBytes(List<SdkBytes> setOfBytesValue)
Create anEnhancedAttributeValue
for a set-of-bytes (bs) DynamoDB type.Equivalent to:
EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().bs(...).build())
This call will fail with a
RuntimeException
if the provided value is null or contains a null value. UsefromListOfAttributeValues(List)
for null values. This will not validate that there are no duplicate values.
-
fromListOfAttributeValues
public static EnhancedAttributeValue fromListOfAttributeValues(AttributeValue... listOfAttributeValuesValue)
Create anEnhancedAttributeValue
for a list-of-attributes (l) DynamoDB type.Equivalent to:
EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().l(...).build())
This call will fail with a
RuntimeException
if the provided value is null or contains a null value. UsenullValue()
for null values.
-
fromListOfAttributeValues
public static EnhancedAttributeValue fromListOfAttributeValues(List<AttributeValue> listOfAttributeValuesValue)
Create anEnhancedAttributeValue
for a list-of-attributes (l) DynamoDB type.Equivalent to:
EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().l(...).build())
This call will fail with a
RuntimeException
if the provided value is null or contains a null value. UsenullValue()
for null values.
-
fromAttributeValue
public static EnhancedAttributeValue fromAttributeValue(AttributeValue attributeValue)
Create anEnhancedAttributeValue
from a generatedAttributeValue
.This call will fail with a
RuntimeException
if the provided value is null (AttributeValue.nul()
is okay).
-
type
public AttributeValueType type()
Retrieve the underlying DynamoDB type of this value, such as String (s) or Number (n).This call should never fail with an
Exception
.
-
convert
public <T> T convert(TypeConvertingVisitor<T> convertingVisitor)
Apply the provided visitor to this item attribute value, converting it into a specific type. This is useful inAttributeConverter
implementations, without having to write a switch statement on thetype()
.Reasons this call may fail with a
RuntimeException
:- If the provided visitor is null.
- If the value cannot be converted by this visitor.
-
isMap
public boolean isMap()
Returns true if the underlying DynamoDB type of this value is a Map (m).This call should never fail with an
Exception
.
-
isString
public boolean isString()
Returns true if the underlying DynamoDB type of this value is a String (s).This call should never fail with an
Exception
.
-
isNumber
public boolean isNumber()
Returns true if the underlying DynamoDB type of this value is a Number (n).This call should never fail with an
Exception
.
-
isBytes
public boolean isBytes()
Returns true if the underlying DynamoDB type of this value is Bytes (b).This call should never fail with an
Exception
.
-
isBoolean
public boolean isBoolean()
Returns true if the underlying DynamoDB type of this value is a Boolean (bool).This call should never fail with an
Exception
.
-
isSetOfStrings
public boolean isSetOfStrings()
Returns true if the underlying DynamoDB type of this value is a Set of Strings (ss).This call should never fail with an
Exception
.
-
isSetOfNumbers
public boolean isSetOfNumbers()
Returns true if the underlying DynamoDB type of this value is a Set of Numbers (ns).This call should never fail with an
Exception
.
-
isSetOfBytes
public boolean isSetOfBytes()
Returns true if the underlying DynamoDB type of this value is a Set of Bytes (bs).This call should never fail with an
Exception
.
-
isListOfAttributeValues
public boolean isListOfAttributeValues()
Returns true if the underlying DynamoDB type of this value is a List of AttributeValues (l).This call should never fail with an
Exception
.
-
isNull
public boolean isNull()
Returns true if the underlying DynamoDB type of this value is Null (null).This call should never fail with an
Exception
.
-
asMap
public Map<String,AttributeValue> asMap()
Retrieve this value as a map.This call will fail with a
RuntimeException
ifisMap()
is false.
-
asString
public String asString()
Retrieve this value as a string.This call will fail with a
RuntimeException
ifisString()
is false.
-
asNumber
public String asNumber()
Retrieve this value as a number. Note: This returns aString
(instead of aNumber
), because that's the generated type from DynamoDB:AttributeValue.n()
.This call will fail with a
RuntimeException
ifisNumber()
is false.
-
asBytes
public SdkBytes asBytes()
Retrieve this value as bytes.This call will fail with a
RuntimeException
ifisBytes()
is false.
-
asBoolean
public Boolean asBoolean()
Retrieve this value as a boolean.This call will fail with a
RuntimeException
ifisBoolean()
is false.
-
asSetOfStrings
public List<String> asSetOfStrings()
Retrieve this value as a set of strings.Note: This returns a
List
(instead of aSet
), because that's the generated type from DynamoDB:AttributeValue.ss()
.This call will fail with a
RuntimeException
ifisSetOfStrings()
is false.
-
asSetOfNumbers
public List<String> asSetOfNumbers()
Retrieve this value as a set of numbers.Note: This returns a
List<String>
(instead of aSet<Number>
), because that's the generated type from DynamoDB:AttributeValue.ns()
.This call will fail with a
RuntimeException
ifisSetOfNumbers()
is false.
-
asSetOfBytes
public List<SdkBytes> asSetOfBytes()
Retrieve this value as a set of bytes.Note: This returns a
List
(instead of aSet
), because that's the generated type from DynamoDB:AttributeValue.bs()
.This call will fail with a
RuntimeException
ifisSetOfBytes()
is false.
-
asListOfAttributeValues
public List<AttributeValue> asListOfAttributeValues()
Retrieve this value as a list of attribute values.This call will fail with a
RuntimeException
ifisListOfAttributeValues()
is false.
-
toAttributeValueMap
public Map<String,AttributeValue> toAttributeValueMap()
Convert thisEnhancedAttributeValue
into a generatedMap<String, AttributeValue>
.This call will fail with a
RuntimeException
ifisMap()
is false.
-
toAttributeValue
public AttributeValue toAttributeValue()
Convert thisEnhancedAttributeValue
into a generatedAttributeValue
.This call should never fail with an
Exception
.
-
-