-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Support decoding to Collection and Map subclasses #1019
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
Merged
Merged
Conversation
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
…ent behavior of being able to provide a Codec for an Iterable that is not a Collection
rozza
requested changes
Oct 20, 2022
I'm of the opinion that if we require the IterableCodec / IterableCodecProvider it should not be deprecated but the suggestion to use the CollectionCodecProvider instead works. If we really want to deprecate it, it might be better to do so it in a separate ticket and refactor our code that requires it and remove it from the default registry (and accept it might break some niche usecases). |
stIncMale
requested changes
Oct 25, 2022
bson/src/test/unit/org/bson/codecs/MapCodecV2Specification.groovy
Outdated
Show resolved
Hide resolved
stIncMale
approved these changes
Oct 27, 2022
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.
JAVA-4742
The main complication to adding this feature is that the existing IterableCodec is not able to extend a class with the parameterized types
<T, C extends Collection<T>>
. The same goes for MapCodec extending a class with the parameterized types<T, M extends Map<String, T>>
. The type system prevents this in the face of the default behavior of using ArrayList and HashMap, respectively, for the existing public constructors. Also, since Iterable does not have anadd
method, it's problematic to add a decode method that supports parameterization with Iterable.I tried a bunch of experiments to get these codecs to work with this new feature, failed, and went with the following approach:
com.mongodb.internal.Iterables
class, for example. )