dimanche 20 janvier 2019

How to know type of Map value Map("key->"value") in Scala?

I have an issue with a value of Map("id"), its could have two types : String or Map[String,String].

Case 1: val a = Map("id" -> "123")
Case 2: val a = Map("id"-> Map("ide"->"abcd"))

I want to do a check with a Match case like this :

def d = a.get("id") match {

  case _:String => "String"
  case _:Map[String,Any] => "Map"


}

Does anyone have an idea of how should I handle this case??





Aucun commentaire:

Enregistrer un commentaire