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)

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 authored Oct 22, 2024
1 parent 8a27730 commit e8e5c97
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 e8e5c97

Please sign in to comment.