I have a scenario where I need to convert a scala Map to a case class object and with help of the following references I was able to achieve it locally (scala version 2.12.13):
But when I tried running the same block of code in Databricks notebook it throws an error:
IllegalArgumentException: Cannot construct instance of '$line23851bc084ae4df7a16bf9c475868d9265.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$Test' (although at least one Creator exists): can only instantiate non-static inner class by using default, no-argument constructor at [Source: UNKNOWN; line: -1, column: -1]
Cluster configuration: Databricks runtime 8.2(Includes Spark 3.1.1, Scala 2.12). Please refer to the screenshot for the complete code.
Workaround (not advisable):
def workaround(map: Map[String, Any]): Test = {
Test(
map("k1").asInstanceOf[Int],
map("k2").asInstanceOf[String],
map("k3").asInstanceOf[String],
)
}
val result = workaround(myMap)
Any thoughts on how to resolve this issue?