mongo-java-driver icon indicating copy to clipboard operation
mongo-java-driver copied to clipboard

JAVA-5342 Fix encoding nullable generics

Open cliffred opened this issue 1 year ago • 0 comments

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 avatar Feb 26 '24 11:02 cliffred