Custom codec not found required by data class in list

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 5.0.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Not Needed
    • 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

      Summary

      Given a data class Foo that has a property of type `kotlinx.datetime.LocalTime`, and another data class Bar that has a property of type `List<Foo>`

      No codec is found for the `LocalTime` despite a custom codec being provided and working when no lists are involved.

       

      Doesn't work

       

      data class Foo(
          val time: LocalTime
      )
      
      data class Bar(
          val foos: List<Foo>
      )
       

       

       

      Works fine

       

      *data class Foo(
          val time: LocalTime
      )
      
      data class Bar(
          val foo: Foo
      )*
      

       

      driver version 4.11.0

      How to Reproduce

      Use the above data classes and try to insert the `Bar` class to a collection with custom codec:

       

      class LocalTimeCodec: Codec<LocalTime> {
      
          override fun encode(writer: BsonWriter, value: LocalTime, encoderContext: EncoderContext) {
              writer.writeString(value.toString())
          }
      
          override fun getEncoderClass(): Class<LocalTime> = LocalTime::class.java
      
          override fun decode(reader: BsonReader, decoderContext: DecoderContext): LocalTime =
              LocalTime.parse(reader.readString())
      } 

       

            Assignee:
            Ross Lawley
            Reporter:
            Carl Holwell
            None
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: