mongo-java-driver
mongo-java-driver copied to clipboard
JAVA-5342 Fix encoding nullable generics
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.