When I try to use enum in custom mapping function in scala it throws the following error
Caused by: java.lang.NoSuchFieldException: MODULE$
at java.lang.Class.getField(Class.java:1703)
at scala.Enumeration.readResolve(Enumeration.scala:61)
When I use string instead of enum values it works perfectly fine but when I do what I did below it throws error. Enum is working perfectly when I try to print the values but throws error in this case.
def parseRow(row: Row): String = {
val id = row.getAs[String](ID)
id match {
case ENUM.val1.toString =>
do something
case ENUM.val2.toString =>
do something
}
df.rdd.map(parseRow).toDF("new_id")
I even tried using withName to extract enum value of id and then in case statement match it with enum values but that gives same error.
I even tried using df instead of rdd but that again throws same error.