Background:
- I use some Java libs which require Java Collections (java.util.ArrayList etc.)
- Input JSON items are dynamic, so I can only use
Map[String, Any]
as the result type to json4s' extract method (viz.parse(json).extract[Map[String, Any]]
)
Exception:
I got an exception from Java libs says java.lang.ClassCastException: scala.collection.immutable.$colon$colon cannot be cast to java.util.ArrayList
Reason:
I guess it is because Json4s just generates scala List
but Java List
for JArray
elements (e.g. ["a", "b", "c"]
=> scala.collection.immutable.List("a", "b", "c")
)
So, the question is how I can handle the case?