Add support for custom AttributeConverters and StringConverters to be used in collections#6128
Open
anasatirbasa wants to merge 1 commit intoaws:masterfrom
Open
Conversation
6b10d44 to
516e50d
Compare
6587bc4 to
c2b6e7c
Compare
1103233 to
4e61fc5
Compare
4e61fc5 to
fdf3b4a
Compare
… used in collections
32b5863 to
1891d84
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License