DynamoDB Enhanced - support for custom AttributeConverters and StringConverters to be used in collections #6128
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added support for custom AttributeConverters and StringConverters in collection types
Motivation and Context
Currently, serializing custom types within collections (like
List<CustomType>
,Set<CustomType>
,Map<CustomType, Value>
orMap<Value, CustomType>
) requires extensive boilerplate or duplication of internal SDK logic. The default converter providers do not support registering custom converters, making it difficult to handle these cases cleanly.This change introduces fallback mechanisms and Jackson-based generic converters to simplify serialization of custom types in collections, improving extensibility and developer experience.
Fixes: #4862
Modifications
Added
GenericObjectStringConverter<T>
: A generic StringConverter that uses Jackson's ObjectMapper to serialize/deserialize custom types to and from JSON strings.Added
FallbackAttributeConverter<T>
: Wraps a StringConverter to enable its use in collections (lists, sets, maps) when no specific AttributeConverter is registered.Added
FallbackStringConverterProvider
: A custom StringConverterProvider that first tries the default provider and falls back to GenericObjectStringConverter using ObjectMapper when needed.Enabled support for custom types in collections: Collection element types and map keys/values can now be serialized/deserialized using fallback converters.
Added tests: Unit and integration tests verifying support for custom object types in List, Set, and Map structures.
Testing
Unit Tests: Verified the behavior of
GenericObjectStringConverter
,FallbackAttributeConverter
, andFallbackStringConverterProvider
, ensuring correct serialization and deserialization of custom types.Integration Tests: correct serialization/deserialization of:
- List of elements of custom type
- Set of elements of custom type
- Map with key of custom type
- Map with values of custom type
Edge Cases: Tested null values, empty collections, and malformed input strings to ensure robustness.
Test Coverage Checklist
Types of changes
Checklist
mvn install
succeedsscripts/new-change
script and following the instructions. Commit the new file created by the script in.changes/next-release
with your changes.License