Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement polymorphism support for DynamoDB entries #3643

Open
wants to merge 3 commits into
base: v4-development
Choose a base branch
from

Conversation

irina-herciu
Copy link
Contributor

@irina-herciu irina-herciu commented Feb 7, 2025

  • implement DynamoDBPolymorphicPropertyAttribute for polymorphism support that should solve Saving nested items with class hierarchies Saving nested items with class hierarchies #2985

  • implement DynamoDBPolymorphicTypeAttribute for polymorphism support for table entries

Description

New DynamoDB PropertyAttribute added as DynamoDBPolymorphicPropertyAttribute in order to add support for polymorphic property types serialization and deserialization
[DynamoDBPolymorphicProperty("B", typeof(B))]

New DynamoDB Attribute added as DynamoDBPolymorphicTypeAttribute in order to add support for polymorphic types serialization and deserialization
[DynamoDBPolymorphicType("A2", typeof(ModelA2))]

Type Attribute name can be configurable from DerivedTypeAttributeName on DynamoDBContextConfig and by default uses "$type".

Motivation and Context

#2985

Testing

Integration tests added

Screenshots (if appropriate)

image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license

implement DynamoDBDerivedTypeAttribute for polymorphism support

update nested items for V4
@dscpinheiro
Copy link
Contributor

Can the other PR (that was targeting V3) - #3633 - be closed?

@irina-herciu
Copy link
Contributor Author

@dscpinheiro the issue that the PR has in scope to fix was affecting AWSSDK.DynamoDBv2 3.7.104, but as @normj instructed in #3633 the fix is raised for V4 also.

@dscpinheiro
Copy link
Contributor

Ok, my read from Norm's comment in the other PR was that we should only make this change for V4.

But I can double-check with him offline.

@normj
Copy link
Member

normj commented Feb 7, 2025

@irina-herciu Can you add a change file like you did in your previous PR. https://github.com/aws/aws-sdk-net/pull/3614/files

@normj
Copy link
Member

normj commented Feb 7, 2025

@irina-herciu A concern I have is a user saves the item with .NET but another parts reads the item with a different language have a mechanism that only stores the .NET type won't be portable. The AWS Kotlin SDK has similar support for polymorphism in their high level. It supports a mechanism customers can use to control the identifier for the type and they could potentially use a language neutral identifier. Can you rework this to have some sort of system that allows users to register a type conversation mapping. By default it can rely on .NET type but if a user can opt-in their own mechanism that would unblock polyglot customers.

Validation should be a customer can save a item using polymorphism in our Kotlin SDK and have a way to read it back out using your changes. My understanding in the Kotlin SDK you use the HeterogenerousItemConverter https://sdk.amazonaws.com/kotlin/api/latest/dynamodb-mapper/aws.sdk.kotlin.hll.dynamodbmapper.items/-heterogeneous-item-converter/index.html

@normj normj self-requested a review February 7, 2025 23:49
@irina-herciu
Copy link
Contributor Author

@normj The functionality implemented of this feature is different from the 'HeterogenerousItemConverter', as the Kotlin SDK feature is designed to convert top-level items in a DynamoDB table, meaning it applies polymorphism only when retrieving or saving items at the root level and requires a custom 'AttributeConverter' to handle polymorphic nested items.

@irina-herciu
Copy link
Contributor Author

@irina-herciu Can you add a change file like you did in your previous PR. https://github.com/aws/aws-sdk-net/pull/3614/files

Change file added

@irina-herciu irina-herciu changed the title implement DynamoDBDerivedTypeAttribute for polymorphism support implement polymorphism support for DynamoDB entries Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants