Skip to content

Fix duplicate field name serialization with @BsonDiscriminator and getter #1610

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

raffaeleflorio
Copy link

@raffaeleflorio raffaeleflorio commented Jan 16, 2025

This PR is about the JAVA-5764 issue. It changes the encode method by skipping the encode of a property if it's already encoded as the discriminator.

@rozza
Copy link
Member

rozza commented Jan 22, 2025

@raffaeleflorio could you include a test case for the issue?

@raffaeleflorio
Copy link
Author

raffaeleflorio commented Jan 22, 2025

@rozza I've just added the test case. The testDiscriminatorEncodedOnceWhenItIsAlsoAGetter fails without the change because the discriminator will be encoded two times instead of one when encoding a DiscriminatorWithModelGetter object.

@raffaeleflorio
Copy link
Author

raffaeleflorio commented Jan 23, 2025

@rozza I also added the testDiscriminatorEncodedOnceWhenItIsAlsoAProperty in order to test a getter with the readName as the discriminationKey. It fails without the fix because the same reasons of the aforesaid test.

@raffaeleflorio
Copy link
Author

Hello @rozza @jyemin, what else could I improve about this PR? Thanks

@jyemin jyemin requested a review from rozza April 24, 2025 11:46
@jyemin jyemin changed the title fix JAVA-5764 Fix duplicate field name serialization with @BsonDiscriminator and getter May 1, 2025
@raffaeleflorio raffaeleflorio force-pushed the main branch 2 times, most recently from b7b2ec1 to e8446d6 Compare May 18, 2025 07:03
@raffaeleflorio raffaeleflorio force-pushed the main branch 2 times, most recently from a6de0b5 to 3ae1b70 Compare May 30, 2025 14:07
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants