Q:

Scala deserialize JSON to Collection

My JSON File containes below details
{
"category":"age, gender,post_code"
}
My scala code is below one
val filename = args.head
println(s"Reading ${args.head} ...")
val json = Source.fromFile(filename)
val mapper = new ObjectMapper() with ScalaObjectMapper
mapper.registerModule(DefaultScalaModule)
val parsedJson = mapper.readValue[Map[String, Any]](json.reader())   
val data = parsedJson.get("category").toSeq

It's returning Seq(Any) = example List(age, gender,post_code) but I need Seq(String) output please if any has an idea about this please help me. 

A:

The idea in scala is to be typesafe whenever possible which you are giving away using Map[String, Any].  
So, I recommend using a data class that represents your JSON data. 
Example, 
define a mapper,
scala> import com.fasterxml.jackson.databind. ObjectMapper
import com.fasterxml.jackson.databind. ObjectMapper

scala> import com.fasterxml.jackson.module.scala.experimental. ScalaObjectMapper
import com.fasterxml.jackson.module.scala.experimental. ScalaObjectMapper

scala> import com.fasterxml.jackson.module.scala. DefaultScalaModule
import com.fasterxml.jackson.module.scala. DefaultScalaModule

scala> val mapper = new ObjectMapper() with ScalaObjectMapper
mapper: com.fasterxml.jackson.databind. ObjectMapper with com.fasterxml.jackson.module.scala.experimental. ScalaObjectMapper = $anon$1@d486a4d

scala> mapper.registerModule(DefaultScalaModule)
res0: com.fasterxml.jackson.databind. ObjectMapper = $anon$1@d486a4d

Now, when you deserialise to Map[K, V] you can not specify all the nested data-structures,
scala> val jsonString = """{"category": ["metal", "metalcore"], "age": 10, "gender": "M", "postCode": "98109"}"""
jsonString: String = {"category": ["metal", "metalcore"], "age": 10, "gender": "M", "postCode": "98109"}

scala> mapper.readValue[Map[String, Any]](jsonString)
res2: Map[String,Any] = Map(category -> List(metal, metalcore), age -> 10, gender -> M, postCode -> 98109)

Following is a solution casting some key to desired data-structure but I personally don not recommend. 
scala> mapper.readValue[Map[String, Any]](jsonString).get("category").map(_.asInstanceOf[List[String]]).getOrElse(List.empty[String])
res3: List[String] = List(metal, metalcore)

Best solution is to define a data class which I'm calling SomeData in following example and deserialize to it.  SomeData is defined based on your JSON data-structure.  
scala> final case class SomeData(category: List[String], age: Int, gender: String, postCode: String)
defined class SomeData

scala> mapper.readValue[SomeData](jsonString)
res4: SomeData = SomeData(List(metal, metalcore),10,M,98109)

scala> mapper.readValue[SomeData](jsonString).category
res5: List[String] = List(metal, metalcore)

