Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-5122

Cannot serialize Array property

    • 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?

      When trying to serialize a class with an array property, e.g.

      ```kotlin
      data class Foo(val myStrings: Array<String>)
      ```

      the BSON serializer fails. This is due to this check in ChildCodecRegistry: https://github.com/mongodb/mongo-java-driver/blob/2fa9f4928c7badc2b022dfc007ce692e82dfe5cd/bson/src/main/org/bson/internal/ChildCodecRegistry.java#L75

      `Class<Array<T>>.getTypeArguments` does not actually return 1 but the same as `Class<T>.getTypeArguments`.

      The simplest fix can be to use `Class.isArray` to hardcode a fallback to one type parameter in that case.

      This happens on the most recent version, 4.10.2.

      This bug is actually somewhat important because Kotlin Multiplatform does not support `List`, the usually more natural choice, and requires you to use `Array` instead.

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            a.tollkoetter@gmx.de Andreas Tollkötter
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: