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
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
  • Loading branch information
rozza committed Oct 15, 2024
1 parent 877425e commit 1f54c4c
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 1f54c4c

Please sign in to comment.