findCodecForType

fun <T> findCodecForType(type: KType, value: Any? = null): Codec<T>(source)

Returns the instance of Codec (from the official MongoDB driver) that is used to encode or decode the given type.

If type and T do not match, the behavior is unspecified. Prefer using the no-argument of this method.

Parameters

value

The value we attempt to encode or decode. If provided, it will be used to enhance the error message. It does not impact the result of this function.

See also

The codec registry used by this BSON factory.

Throws

If no matching codec is found for the given type.


inline fun <T> findCodecForType(): Codec<T>(source)
inline fun <T> findCodecForType(value: T): Codec<T>(source)

Returns the instance of Codec (from the official MongoDB driver) that is used to encode or decode the given type T.

Example

val client = MongoClient.create("mongodb://mongo:27017")
val factory = BsonFactory(client.codecRegistry)

val codec = factory.findCodecForType<String>()

See also

The codec registry used by this BSON factory.

Throws

If no matching codec is found for the given type.