Skip to content

Commit

Permalink
Ensure kotlinx.datetime.LocalTime exists before adding the serializer (
Browse files Browse the repository at this point in the history
…#1530) (#1559)

LocalTime was added in kotlinx.datetime v0.4.0 and won't be available
if older versions of kotlinx datetime are on the classpath.

JAVA-5641

Co-authored-by: Ross Lawley <ross@mongodb.com>
  • Loading branch information
katcharov and rozza authored Nov 5, 2024
1 parent d3190ff commit c0fcd61
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,16 @@ import org.bson.codecs.kotlinx.utils.SerializationModuleUtils.isClassAvailable
public val dateTimeSerializersModule: SerializersModule by lazy {
var module = SerializersModule {}
if (isClassAvailable("kotlinx.datetime.Instant")) {
module +=
InstantAsBsonDateTime.serializersModule +
LocalDateAsBsonDateTime.serializersModule +
LocalDateTimeAsBsonDateTime.serializersModule +
LocalTimeAsBsonDateTime.serializersModule
module += InstantAsBsonDateTime.serializersModule
}
if (isClassAvailable("kotlinx.datetime.LocalDate")) {
module += LocalDateAsBsonDateTime.serializersModule
}
if (isClassAvailable("kotlinx.datetime.LocalDateTime")) {
module += LocalDateTimeAsBsonDateTime.serializersModule
}
if (isClassAvailable("kotlinx.datetime.LocalTime")) {
module += LocalTimeAsBsonDateTime.serializersModule
}
module
}
Expand Down

0 comments on commit c0fcd61

Please sign in to comment.