@@ -6,13 +6,14 @@ package com.microsoft.azure.synapse.ml.param
66import org .apache .spark .annotation .DeveloperApi
77import org .apache .spark .ml .param .{Param , ParamPair , Params }
88import spray .json .{DefaultJsonProtocol , JsValue , JsonFormat , _ }
9- import org .json4s .DefaultFormats
109
1110import scala .collection .JavaConverters ._
1211
1312object 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