From adddd90a1dea0129df7095980cf11fdaf2c02dda Mon Sep 17 00:00:00 2001 From: Ian De Silva Date: Thu, 2 Nov 2023 09:40:08 -0500 Subject: [PATCH] UUIDSerializer: Change type cast to parent type to fix issues using within a list. The UUIDSerializer's deserializer will fail with a `ClassCastException` when the UUID is embedded in a list (e.g., `val foo: Collection<@Contextual UUID> = emptyList()`). The decoder in this example is a `ListDecoder` rather than the expected `BsonFlexibleDecoder` triggering the exception. Both, however, are `FlexibleDecoder` objects and the reader field is declared there. Updated the cast to this parent type, resolving the issue. --- kmongo-serialization-mapping/src/main/kotlin/Serializers.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kmongo-serialization-mapping/src/main/kotlin/Serializers.kt b/kmongo-serialization-mapping/src/main/kotlin/Serializers.kt index 8bb27f9d..1898e9d6 100644 --- a/kmongo-serialization-mapping/src/main/kotlin/Serializers.kt +++ b/kmongo-serialization-mapping/src/main/kotlin/Serializers.kt @@ -346,7 +346,7 @@ internal object UUIDSerializer : KSerializer { override val descriptor: SerialDescriptor = buildClassSerialDescriptor("UuidSerializer") override fun deserialize(decoder: Decoder): UUID = - (decoder as BsonFlexibleDecoder).reader.readBinaryData().asUuid() + (decoder as FlexibleDecoder).reader.readBinaryData().asUuid() override fun serialize(encoder: Encoder, value: UUID) { (encoder as BsonEncoder).encodeUUID(value)