public interface EnhancedDocument
Enhanced Document with default attribute Converter to convert the attribute of DDB item to basic default primitive types in Java
Enhanced Document with Custom attribute Converter to convert the attribute of DDB Item to Custom Type.
Enhanced Document can be created with Json as input using Static factory method.In this case it used
defaultConverterProviders.
The attribute converter are always required to be provided, thus for default conversion
AttributeConverterProvider.defaultProvider()
must be supplied.
Modifier and Type | Interface and Description |
---|---|
static interface |
EnhancedDocument.Builder |
Modifier and Type | Method and Description |
---|---|
List<AttributeConverterProvider> |
attributeConverterProviders() |
static EnhancedDocument.Builder |
builder()
Creates a default builder for
EnhancedDocument . |
static EnhancedDocument |
fromAttributeValueMap(Map<String,AttributeValue> attributeValueMap)
Creates a new
EnhancedDocument instance from a AttributeValue Map. |
static EnhancedDocument |
fromJson(String json)
Creates a new
EnhancedDocument instance from a JSON string. |
<T> T |
get(String attributeName,
Class<T> clazz)
Returns the value of the specified attribute in the current document as a specified class type; or null if the
attribute either doesn't exist or the attribute value is null.
|
<T> T |
get(String attributeName,
EnhancedType<T> type)
Returns the value of the specified attribute in the current document as a specified
EnhancedType ; or null if the
attribute either doesn't exist or the attribute value is null. |
Boolean |
getBoolean(String attributeName)
Gets the
Boolean value for the specified attribute. |
SdkBytes |
getBytes(String attributeName)
Gets the
SdkBytes value of specified attribute in the document. |
Set<SdkBytes> |
getBytesSet(String attributeName)
Gets the Set of String values of the given attribute in the current document.
|
String |
getJson(String attributeName)
Gets the JSON document value of the specified attribute.
|
<T> List<T> |
getList(String attributeName,
EnhancedType<T> type)
Gets the List of values of type T for the given attribute in the current document.
|
List<AttributeValue> |
getListOfUnknownType(String attributeName)
Retrieves a list of
AttributeValue objects for a specified attribute in a document. |
<K,V> Map<K,V> |
getMap(String attributeName,
EnhancedType<K> keyType,
EnhancedType<V> valueType)
Returns a map of a specific Key-type and Value-type based on the given attribute name, key type, and value type.
|
Map<String,AttributeValue> |
getMapOfUnknownType(String attributeName)
Retrieves a Map with String keys and corresponding AttributeValue objects as values for a specified attribute in a
document.
|
SdkNumber |
getNumber(String attributeName)
Gets the
SdkNumber value of specified attribute in the document. |
Set<SdkNumber> |
getNumberSet(String attributeName)
Gets the Set of String values of the given attribute in the current document.
|
String |
getString(String attributeName)
Gets the String value of specified attribute in the document.
|
Set<String> |
getStringSet(String attributeName)
Gets the Set of String values of the given attribute in the current document.
|
boolean |
isNull(String attributeName)
Checks if the document is a
null value. |
boolean |
isPresent(String attributeName)
Checks if the attribute exists in the document.
|
EnhancedDocument.Builder |
toBuilder()
Converts an existing EnhancedDocument into a builder object that can be used to modify its values and then create a new
EnhancedDocument.
|
String |
toJson() |
Map<String,AttributeValue> |
toMap()
This method converts a document into a key-value map with the keys as String objects and the values as AttributeValue
objects.
|
static EnhancedDocument fromJson(String json)
EnhancedDocument
instance from a JSON string.
The AttributeConverterProvider.defaultProvider()
is used as the default ConverterProvider.
To use a custom ConverterProvider, use the builder methods: EnhancedDocument.Builder.json(String)
to supply the JSON string,
then use EnhancedDocument.Builder.attributeConverterProviders(AttributeConverterProvider...)
to provide the custom
ConverterProvider.
json
- The JSON string representation of a DynamoDB Item.IllegalArgumentException
- if the json parameter is nullstatic EnhancedDocument fromAttributeValueMap(Map<String,AttributeValue> attributeValueMap)
EnhancedDocument
instance from a AttributeValue Map.
The AttributeConverterProvider.defaultProvider()
is used as the default ConverterProvider.
Example usage:
);
}attributeValueMap
- - Map with Attributes as String keys and AttributeValue as Value.IllegalArgumentException
- if the json parameter is nullstatic EnhancedDocument.Builder builder()
EnhancedDocument
.EnhancedDocument.Builder toBuilder()
EnhancedDocument.Builder
initialized with the values of this EnhancedDocument.boolean isNull(String attributeName)
null
value.attributeName
- Name of the attribute that needs to be checked.boolean isPresent(String attributeName)
attributeName
- Name of the attribute that needs to be checked.<T> T get(String attributeName, EnhancedType<T> type)
EnhancedType
; or null if the
attribute either doesn't exist or the attribute value is null.
Retrieving String Type for a document Retrieving Custom Type for which Convertor Provider was defined while creating the document Retrieving list of strings in a document Retrieving a Map with List of strings in its values
T
- The type of the attribute value.attributeName
- Name of the attribute.type
- EnhancedType of the value<T> T get(String attributeName, Class<T> clazz)
Retrieving String Type for a document Retrieving Custom Type for which Convertor Provider was defined while creating the document
Note : This API should not be used to retrieve values of List and Map types. Instead, getList and getMap APIs should be used to retrieve attributes of type List and Map, respectively.
T
- The type of the attribute value.attributeName
- Name of the attribute.clazz
- Class type of value.String getString(String attributeName)
attributeName
- Name of the attribute.SdkNumber getNumber(String attributeName)
SdkNumber
value of specified attribute in the document.attributeName
- Name of the attribute.SdkBytes getBytes(String attributeName)
SdkBytes
value of specified attribute in the document.attributeName
- Name of the attribute.Set<String> getStringSet(String attributeName)
attributeName
- the name of the attribute.Set<SdkNumber> getNumberSet(String attributeName)
attributeName
- Name of the attribute.Set<SdkBytes> getBytesSet(String attributeName)
attributeName
- Name of the attribute.<T> List<T> getList(String attributeName, EnhancedType<T> type)
T
- Type T of List elementsattributeName
- Name of the attribute.type
- EnhancedType
of Type T.<K,V> Map<K,V> getMap(String attributeName, EnhancedType<K> keyType, EnhancedType<V> valueType)
UUID
keys and Integer
values, use this API
as shown below:
K
- The type of the Map keys.V
- The type of the Map values.attributeName
- The name of the attribute that needs to be get as Map.keyType
- Enhanced Type of Key attribute, like String, UUID etc that can be represented as String Keys.valueType
- Enhanced Type of Values , which have converters defineds in
EnhancedDocument.Builder.attributeConverterProviders(AttributeConverterProvider...)
for the documentString getJson(String attributeName)
attributeName
- Name of the attribute.Boolean getBoolean(String attributeName)
Boolean
value for the specified attribute.attributeName
- Name of the attribute.RuntimeException
- if the attribute value cannot be converted to a Boolean representation.
Note that the Boolean representation of 0 and 1 in Numbers and "0" and "1" in Strings is false and true,
respectively.List<AttributeValue> getListOfUnknownType(String attributeName)
AttributeValue
objects for a specified attribute in a document.
This API should be used when the elements of the list are a combination of different types such as Strings, Maps,
and Numbers.
If all elements in the list are of a known fixed type, use getList(String, EnhancedType)
instead.attributeName
- Name of the attribute.AttributeValue
Map<String,AttributeValue> getMapOfUnknownType(String attributeName)
attributeName
- Name of the attribute.AttributeValue
String toJson()
Map<String,AttributeValue> toMap()
List<AttributeConverterProvider> attributeConverterProviders()
Copyright © 2023. All rights reserved.