Skip to content

Commit 30962e2

Browse files
committed
fix: Remove case matching on erased generic type
1 parent 532a9fb commit 30962e2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

core/src/main/scala/com/microsoft/azure/synapse/ml/param/UntypedArrayParam.scala

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ package com.microsoft.azure.synapse.ml.param
66
import org.apache.spark.annotation.DeveloperApi
77
import org.apache.spark.ml.param.{Param, ParamPair, Params}
88
import spray.json.{DefaultJsonProtocol, JsValue, JsonFormat, _}
9-
import org.json4s.DefaultFormats
109

1110
import scala.collection.JavaConverters._
1211

1312
object AnyJsonFormat extends DefaultJsonProtocol {
1413

15-
implicit def anyFormat: JsonFormat[Any] =
14+
implicit def anyFormat: JsonFormat[Any] = {
15+
def throwFailure(any: Any) = throw new IllegalArgumentException(s"Cannot serialize ${any} of type ${any.getClass}")
16+
1617
new JsonFormat[Any] {
1718
def write(any: Any): JsValue = any match {
1819
case v: Int => v.toJson
@@ -21,8 +22,15 @@ object AnyJsonFormat extends DefaultJsonProtocol {
2122
case v: Boolean => v.toJson
2223
case v: Integer => v.toLong.toJson
2324
case v: Seq[_] => seqFormat[Any].write(v)
24-
case v: Map[String, _] => mapFormat[String, Any].write(v)
25-
case _ => throw new IllegalArgumentException(s"Cannot serialize ${any} of type ${any.getClass}")
25+
case v: Map[_, _] => {
26+
try {
27+
mapFormat[String, Any].write(v.asInstanceOf[Map[String, _]])
28+
}
29+
catch {
30+
case _: SerializationException => throwFailure(any)
31+
}
32+
}
33+
case _ => throwFailure(any)
2634
}
2735

2836
def read(value: JsValue): Any = value match {

0 commit comments

Comments
 (0)