Skip to content

Kotlinx serialization decoding optional ObjectId / BsonValues fails to hydrate properly #1143

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 3 commits into from
Jun 20, 2023

Conversation

rozza
Copy link
Member

@rozza rozza commented Jun 16, 2023

Found when writing the documentation:

The DefaultBsonDecoder required extra handling to ensure it did not try to double decode optional values and overwrite them with a null value.

Tracking currentIndex and processed status allows the default decoder to correctly track if all elements have been processed and report the correct value when calling decodeElementIndex.

JAVA-5031

…o hydrate

The DefaultBsonDecoder required extra handling to ensure it did not
double decode optional values and overwrite them with a null value.

Tracking currentIndex and processed status allows the default decoder
to correctly track if all elements have been processed and report
the correct value when calling decodeElementIndex.

JAVA-5031
@rozza rozza requested a review from jyemin June 16, 2023 15:12
fun testDataClassWithOptionalObjectIdAndBsonDocument() {
val subDocument =
"""{
| "_id": 1,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me why it's necessary to test with such a complex subdocument. What's being tested by this? The fact that I don't know makes me think I don't understand the issue.

Copy link
Member Author

@rozza rozza Jun 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The subdocument is just copy-pasta.

I'll update the tests and move to a val.

@rozza
Copy link
Member Author

rozza commented Jun 19, 2023

Updated the test cases and simplified the decoder.

decodeElementIndex now correctly returns all indexes for fields even if they aren't present in the data.

@rozza rozza merged commit c5370c3 into mongodb:master Jun 20, 2023
@rozza rozza deleted the JAVA-5031 branch June 20, 2023 15:04
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.

2 participants