@@ -23,6 +23,7 @@ import org.bson.codecs.DecoderContext
2323import org.bson.codecs.EncoderContext
2424import org.bson.codecs.configuration.CodecConfigurationException
2525import org.bson.codecs.configuration.CodecRegistries.fromProviders
26+ import org.bson.codecs.kotlin.samples.Box
2627import org.bson.codecs.kotlin.samples.DataClassEmbedded
2728import org.bson.codecs.kotlin.samples.DataClassListOfDataClasses
2829import org.bson.codecs.kotlin.samples.DataClassListOfListOfDataClasses
@@ -55,6 +56,7 @@ import org.bson.codecs.kotlin.samples.DataClassWithMutableMap
5556import org.bson.codecs.kotlin.samples.DataClassWithMutableSet
5657import org.bson.codecs.kotlin.samples.DataClassWithNestedParameterized
5758import org.bson.codecs.kotlin.samples.DataClassWithNestedParameterizedDataClass
59+ import org.bson.codecs.kotlin.samples.DataClassWithNullableGeneric
5860import org.bson.codecs.kotlin.samples.DataClassWithNulls
5961import org.bson.codecs.kotlin.samples.DataClassWithObjectIdAndBsonDocument
6062import org.bson.codecs.kotlin.samples.DataClassWithPair
@@ -131,6 +133,25 @@ class DataClassCodecTest {
131133 assertDecodesTo(withStoredNulls, dataClass)
132134 }
133135
136+ @Test
137+ fun testDataClassWithNullableGenericsNotNull () {
138+ val expected =
139+ """ {
140+ | "box": {"boxed": "String"}
141+ |}"""
142+ .trimMargin()
143+
144+ val dataClass = DataClassWithNullableGeneric (Box (" String" ))
145+ assertRoundTrips(expected, dataClass)
146+ }
147+
148+ @Test
149+ fun testDataClassWithNullableGenericsNull () {
150+ val expected = """ {"box": {}}"""
151+ val dataClass = DataClassWithNullableGeneric (Box (null ))
152+ assertRoundTrips(expected, dataClass)
153+ }
154+
134155 @Test
135156 fun testDataClassSelfReferential () {
136157 val expected =
0 commit comments