If I have a java.util.Map[String,Java.util.Map]
for the first call, correct overloaded method is called: toScala(java.util.Map[_,_])
. But in the mapValues invocation, function toScala(other:Any)
is called. How to avoid this?
I would be calling toScala using a java object like Map, List, Int, String. The map may contain another java.util.Map/java.util.List/ String/Int
as one of its values. Similarly the list may also contain another java.util.List/ String/ Int
as its members
private def toScala(map:java.util.Map[_,_]) : Any = {
map match {
case null => Map.empty
case _ => map.asScala.mapValues(toScala).toMap
}
}
private def toScala(list:java.util.List[_]) : Any = {
list match {
case null => List.empty
case _ => list.asScala.map(toScala).toList
}
}
private def toScala(other:Any) : Any = {
other match {
case null => None
case _ => other
}
}