DynamoDB Enhanced Client Polymorphic Types Support #6271
+2,533
−100
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.
Motivation and Context
By default, the
DynamoDbEnhancedClient
does not natively support storing multiple Java subclasses of a common supertype in the same table. In complex domain models (e.g. storing bothEmployee
andCustomer
instances ofPerson
), there was a need to write complex type‐discrimination logic. This change introduces a clean, annotation‐driven layer that automatically dispatches to the correct subtype schema at runtime, reducing boilerplate and eliminating fragile manual checks.Modifications
@DynamoDbSubtypeDiscriminator
to mark the discriminator field on the base type.@DynamoDbSupertype
(with innerSubtype
annotation) to declare each concrete subtype and its discriminator value on the supertype class.StaticAttributeTags.subtypeName()
andSubtypeNameTag
to record the discriminator attribute name inTableMetadata
.StaticSubtype<T>
encapsulates a subtype’sTableSchema
and its discriminator value.StaticPolymorphicTableSchema<T>
implementsTableSchema<T>
: reads the discriminator from the item or object, looks up the rightStaticSubtype
, and delegates all mapping calls.PolymorphicTableSchema<T>
wraps the static polymorphic schema for recursive resolution and caching.TableSchemaFactory.fromClass(...)
to detect@DynamoDbSupertype
and route toPolymorphicTableSchema.create(...)
.EnhancedClientUtils.readAndTransformSingleItem
and all core operations (Put, Update, Transact) to resolve and use the concrete subtype schema before invoking extensions or building requests.converterForAttribute(...)
inStaticPolymorphicTableSchema
to delegate to the root schema so user‐defined@DynamoDbConvertedBy
converters continue to work seamlessly.Testing
StaticPolymorphicTableSchema
covering:mapToItem
/itemToMap
).Instant
) are correctly applied viaconverterForAttribute
.Person
andCustomer
subclasses.beforeWrite
/afterRead
.Screenshots (if appropriate)
(See design doc diagrams in Section 4 and 5 for visual routing and flowchart illustrations.)
Test Coverage Checklist
Types of changes
Checklist
mvn install
succeedsscripts/new-change
script and following the instructions.License