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

JAVA-5342 Fix encoding nullable generics #1317

Merged
merged 1 commit into from
Jul 1, 2024

Conversation

cliffred
Copy link
Contributor

@cliffred cliffred commented Feb 26, 2024

Encoding a generic class object with a nullable type parameter, like DataClassWithNullableGeneric, will fail with org.bson.BsonInvalidOperationException: writeString can only be called when State is VALUE, not when State is NAME or org.bson.BsonInvalidOperationException: writeNull can only be called when State is VALUE, not when State is NAME depending on whether boxed is null.

@Serializable data class Box<T>(val boxed: T)
@Serializable data class DataClassWithNullableGeneric(val box: Box<String?>)

JAVA-5342

@cliffred cliffred changed the title Fix encoding nullable generics JAVA-5342 Fix encoding nullable generics Feb 28, 2024
@cliffred cliffred force-pushed the nullable-generics branch from 5b1db72 to 163996f Compare March 21, 2024 16:05
@cliffred cliffred force-pushed the nullable-generics branch from 163996f to 6f9ad09 Compare May 16, 2024 08:10
@cliffred cliffred force-pushed the nullable-generics branch from 6f9ad09 to 87bdd1f Compare June 17, 2024 09:18
Copy link
Member

@rozza rozza left a comment

Choose a reason for hiding this comment

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

LGTM

@rozza rozza merged commit 0282a7e into mongodb:master Jul 1, 2024
2 of 3 checks passed
@rozza
Copy link
Member

rozza commented Jul 1, 2024

Many thanks @cliffred this will be in the next release.

rozza pushed a commit to rozza/mongo-java-driver that referenced this pull request Jul 1, 2024
rozza pushed a commit to rozza/mongo-java-driver that referenced this pull request Jul 3, 2024
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