Add contextual serializer for kotlin.date.Instant

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: Kotlin
    • None
    • Java Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      The MongoDB Kotlin driver supports contextual serializers for the kotlinx.datetime library using the @Contextual annotation from kotlinx-serialization. Since Kotlin version 2.1 these types have moved from kotlinx-datetime to the Kotlin stdlib and are thus deprecated.

      // works for now, but deprecated
      data class SomeClass(
          @Contextual val someInstant: kotlinx.datetime.Instant,
      )
       // will throw a runtime exception
      data class SomeClass(
          @Contextual val someInstant: kotlin.time.Instant,
      )
      

      It would be nice to have @Contextual support for the new stdlib classes such as kotlin.date.Instant out of the box.

      Workaround in the meantime: Create your custom serializer. 

              Assignee:
              Nabil Hachicha
              Reporter:
              Richard Schielek
              None
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated: