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

Make DefaultSdkAutoConstructList/Map Serializable. #5936

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ryucc
Copy link

@ryucc ryucc commented Mar 6, 2025

Motivation and Context

See Issue #3143

Classes AttributeValue, S3Object, DynamoDb GetItemRequest implement the Serializable interface, but throws a NotSerializableException since v2.

This is due to using DefaultSdkAutoConstructList/Map as member field. When a Map/List does not exist in the request, These DefaultSdkAutoConstruct represent the non-existence, in contrary to an existing but empty List/Map.

There is a 4 line fix, to make these 2 classes Serializable. The challenge here is that they are both singleton classes. Java provides a readResolve() interface to handle this case.

The official documentation is here:
https://docs.oracle.com/en/java/javase/17/docs/specs/serialization/input.html

Other 3rd party references:
https://www.baeldung.com/java-serialization-readobject-vs-readresolve
https://stackoverflow.com/questions/3930181/how-to-deal-with-singleton-along-with-serialization

This feature is available since java 8:
https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html

Modifications

Make DefaultSdkAutoConstructList/Map Serializable.

  • Add the Serializable to both classes
  • Implement the readResolve() method, to return the singleton INSTANCE.
  • Add unit test, testing serialization/deserialization is working, and the deserialized result is not a new instance.

Testing

  • New unit tests implemented

java version "1.8.0_441"
Java(TM) SE Runtime Environment (build 1.8.0_441-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.441-b07, mixed mode)
Darwin **** 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:19:22 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8112 arm64

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

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

The usage of DefaultSdkAutoConstruct blocks Serialization of
AttributeValue, S3Object, DynamoDb GetItemRequest.

See Issue aws#3143
@ryucc ryucc requested a review from a team as a code owner March 6, 2025 08:35
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.

1 participant