Uploaded image for project: 'Scala'
  1. Scala
  2. SCALA-346

ClassCastException while trying to decode a case class with a parameter of type scala.immutable.Set

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.7.0
    • Component/s: bson
    • Labels:
      None

      Description

      Executing find() on a MongoCollection[ModelDocument] results in ClassCastException if the ModelDocument contains a parameter of Set datatype (that also seems to extend to a scala.immutable.Map, and not necessarily for just the immutable types)

      Please find the test file attached, to reproduce the error (Changes needed w.r.t specifying the MongoDb host and database/collection names.

      It seems the decode() method in MacroCodec.scala is unable to create an instance of the Set class, since it defaults to a List datatype while reading from the database.

      The only other resource I found w.r.t this error was https://stackoverflow.com/questions/45860327/how-can-i-save-set-with-mongo-scala-driver.

      This is reproduce-able using the mongo-scala-driver version 2.1.0, haven't tried with older versions on my side.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: