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 generated AttributeValue.

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 the type() method or the is* methods like isString() or isNumber(). Once the type is known, the value can be extracted with as* methods like asString() or asNumber().

When converting an EnhancedAttributeValue into a concrete Java type, it can be tedious to use the type() or is* methods. For this reason, a convert(TypeConvertingVisitor) method is provided that exposes a polymorphic way of converting a value into another type.

An instance of EnhancedAttributeValue is created with the from* methods, like fromString(String) or fromNumber(String).

  • Method Details

    • nullValue

      public static EnhancedAttributeValue nullValue()
      Create an EnhancedAttributeValue 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 an EnhancedAttributeValue 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 an EnhancedAttributeValue 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. Use nullValue() for null values.

    • fromNumber

      public static EnhancedAttributeValue fromNumber(String numberValue)
      Create an EnhancedAttributeValue 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. Use nullValue() for null values.

    • fromBytes

      public static EnhancedAttributeValue fromBytes(SdkBytes bytesValue)
      Create an EnhancedAttributeValue 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. Use nullValue() for null values.

    • fromBoolean

      public static EnhancedAttributeValue fromBoolean(Boolean booleanValue)
      Create an EnhancedAttributeValue 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. Use nullValue() for null values.

    • fromSetOfStrings

      public static EnhancedAttributeValue fromSetOfStrings(String... setOfStringsValue)
      Create an EnhancedAttributeValue 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. Use fromListOfAttributeValues(List) for null values. This will not validate that there are no duplicate values.

    • fromSetOfStrings

      public static EnhancedAttributeValue fromSetOfStrings(Collection<String> setOfStringsValue)
      Create an EnhancedAttributeValue 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. Use fromListOfAttributeValues(List) for null values. This will not validate that there are no duplicate values.

    • fromSetOfStrings

      public static EnhancedAttributeValue fromSetOfStrings(List<String> setOfStringsValue)
      Create an EnhancedAttributeValue 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. Use fromListOfAttributeValues(List) for null values. This will not validate that there are no duplicate values.

    • fromSetOfNumbers

      public static EnhancedAttributeValue fromSetOfNumbers(String... setOfNumbersValue)
      Create an EnhancedAttributeValue 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. Use fromListOfAttributeValues(List) for null values. This will not validate that there are no duplicate values.

    • fromSetOfNumbers

      public static EnhancedAttributeValue fromSetOfNumbers(Collection<String> setOfNumbersValue)
      Create an EnhancedAttributeValue 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. Use fromListOfAttributeValues(List) for null values. This will not validate that there are no duplicate values.

    • fromSetOfNumbers

      public static EnhancedAttributeValue fromSetOfNumbers(List<String> setOfNumbersValue)
      Create an EnhancedAttributeValue 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. Use fromListOfAttributeValues(List) for null values. This will not validate that there are no duplicate values.

    • fromSetOfBytes

      public static EnhancedAttributeValue fromSetOfBytes(Collection<SdkBytes> setOfBytesValue)
      Create an EnhancedAttributeValue 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. Use fromListOfAttributeValues(List) for null values. This will not validate that there are no duplicate values.

    • fromSetOfBytes

      public static EnhancedAttributeValue fromSetOfBytes(SdkBytes... setOfBytesValue)
      Create an EnhancedAttributeValue 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. Use fromListOfAttributeValues(List) for null values. This will not validate that there are no duplicate values.

    • fromSetOfBytes

      public static EnhancedAttributeValue fromSetOfBytes(List<SdkBytes> setOfBytesValue)
      Create an EnhancedAttributeValue 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. Use fromListOfAttributeValues(List) for null values. This will not validate that there are no duplicate values.

    • fromListOfAttributeValues

      public static EnhancedAttributeValue fromListOfAttributeValues(AttributeValue... listOfAttributeValuesValue)
      Create an EnhancedAttributeValue 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. Use nullValue() for null values.

    • fromListOfAttributeValues

      public static EnhancedAttributeValue fromListOfAttributeValues(List<AttributeValue> listOfAttributeValuesValue)
      Create an EnhancedAttributeValue 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. Use nullValue() for null values.

    • fromAttributeValue

      public static EnhancedAttributeValue fromAttributeValue(AttributeValue attributeValue)
      Create an EnhancedAttributeValue from a generated AttributeValue.

      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 in AttributeConverter implementations, without having to write a switch statement on the type().

      Reasons this call may fail with a RuntimeException:

      1. If the provided visitor is null.
      2. 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 if isMap() is false.

    • asString

      public String asString()
      Retrieve this value as a string.

      This call will fail with a RuntimeException if isString() is false.

    • asNumber

      public String asNumber()
      Retrieve this value as a number. Note: This returns a String (instead of a Number), because that's the generated type from DynamoDB: AttributeValue.n().

      This call will fail with a RuntimeException if isNumber() is false.

    • asBytes

      public SdkBytes asBytes()
      Retrieve this value as bytes.

      This call will fail with a RuntimeException if isBytes() is false.

    • asBoolean

      public Boolean asBoolean()
      Retrieve this value as a boolean.

      This call will fail with a RuntimeException if isBoolean() is false.

    • asSetOfStrings

      public List<String> asSetOfStrings()
      Retrieve this value as a set of strings.

      Note: This returns a List (instead of a Set), because that's the generated type from DynamoDB: AttributeValue.ss().

      This call will fail with a RuntimeException if isSetOfStrings() is false.

    • asSetOfNumbers

      public List<String> asSetOfNumbers()
      Retrieve this value as a set of numbers.

      Note: This returns a List<String> (instead of a Set<Number>), because that's the generated type from DynamoDB: AttributeValue.ns().

      This call will fail with a RuntimeException if isSetOfNumbers() is false.

    • asSetOfBytes

      public List<SdkBytes> asSetOfBytes()
      Retrieve this value as a set of bytes.

      Note: This returns a List (instead of a Set), because that's the generated type from DynamoDB: AttributeValue.bs().

      This call will fail with a RuntimeException if isSetOfBytes() is false.

    • asListOfAttributeValues

      public List<AttributeValue> asListOfAttributeValues()
      Retrieve this value as a list of attribute values.

      This call will fail with a RuntimeException if isListOfAttributeValues() is false.

    • toAttributeValueMap

      public Map<String,AttributeValue> toAttributeValueMap()
      Convert this EnhancedAttributeValue into a generated Map<String, AttributeValue>.

      This call will fail with a RuntimeException if isMap() is false.

    • toAttributeValue

      public AttributeValue toAttributeValue()
      Convert this EnhancedAttributeValue into a generated AttributeValue.

      This call should never fail with an Exception.

    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object