-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: 5.6.2
-
Component/s: BSON
-
None
-
None
-
Java Drivers
-
None
-
None
-
None
-
None
-
None
-
None
Summary
I want to deserialize a Kotlin class with type parameters, using the `org.mongodb:bson-kotlin` (reflection-based) driver.
My understanding is that I should call the `CodecProvider.get(Class<T>, List<Type>)` overload to specify the type parameters; since they are removed at compile-time, the reflection-based implementation cannot figure them out by itself.
I therefore have the following type:
data class BsonDocumentUser(
val a: String = "Bob",
val b: Int,
)
data class BsonDocumentTypeParameter<T>(
val value: T,
)
codecRegistry.get(BsonDocumentTypeParameter::class, listOf(BsonDocumentUser::class))
However, this does not return the codec.
Looking at the implementation:
- In `org.bson.internal.ProvidersCodecRegistry#get(java.lang.Class<T>, java.util.List<java.lang.reflect.Type>)`, a new ChildCodecRegistry is created, but does nothing
- In `org.bson.internal.ProvidersCodecRegistry#get(org.bson.internal.ChildCodecRegistry<T>)`, a new CodecCacheKey is created.
- Immediately, `org.bson.internal.CodecCache#get` is called on the new cache key.
At this point, `org.bson.internal.CodecCache#putIfAbsent` has not been called, so of course the codec cache returns null.
Am I supposed to register the type somewhere so the codec cache is populated in advance? Is there something else I'm doing wrong?
Versions
- Java driver 5.6.2
- The MongoDB server version & topology should not impact this; I'm using 7.0.31 standalone