Skip to content

Commit

Permalink
UUIDSerializer: Change type cast to parent type to fix issues using w…
Browse files Browse the repository at this point in the history
…ithin 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.
  • Loading branch information
desilvai-target authored and zigzago committed Nov 7, 2023
1 parent 83542f2 commit eefb061
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ internal object UUIDSerializer : KSerializer<UUID> {
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)
Expand Down

0 comments on commit eefb061

Please sign in to comment.