A word of warning: the original Codahale Jerkson
has been abandoned and there's no official build for Scala 2.10 (although there are some Github forks for 2.10). jackson-module-scala
(which jerkson
wraps), on the other hand, is fully maintained and supported.
[EDIT] after clarifying the question.
The original data structure is using List
s of Any
(List
s and String
s). The one that's returned from the parser is List
, but lists inside of it arejava.util.ArrayList
. That type is also a list, but not the same and doesn't fit in to Scala collections as natively. Among other things, it has a different implementation of toString
, which is why the output is different. Note that it's still a list of Any
, just not the Scala List
s.
One way to solve it would be just to use collection converters to convert to Scala:
import scala.collection.JavaConverters._
// somewhere down the line
val parsedList = parse[List[Any]](json_ver)
parsedList.foreach {
case s: String => println("string: " + s)
case l: util.ArrayList[Any] => doSomething(l.asScala.toList)
}
...
def doSomething(lst: List[Any]) {
println(lst)
}
Another way is that if you were to use Jackson, you could configure it to use Java arrays:
val mapper = new ObjectMapper()
mapper.configure(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY, true)
mapper.registerModule(DefaultScalaModule)
mapper.readValue[List[Any]](json_ver, classOf[List[Any]])