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

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

Conversation

cliffred
Copy link

@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?>)

This PR fixes this.

@cliffred cliffred changed the title Fix encoding nullable generics JAVA-5342 Fix encoding nullable generics Feb 28, 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
1 participant