I have to deconstruct the following JSON into a list of case classes:
{
"data": [
[49, true, 14, null, null],
[52, false, null, null, null],
[72, true, 4, 2, 1]
]
}
case class:
case class Data(i1: Int, b: Bool, i2: Option[Int], i3: Option[Int], i4: Option[Int])
I started with a for comprehension, but was not able to finish it:
for {
JArray(data) <- json \ "data"
JArray(d) <- data
JInt(line) <- d.head // ???
} yield Data()
Any help is much appreciated.
Thanks,
Michael
You can write a
CustomSerializer
forData
.I introduced a
JOptionInt
extractor to turn aJInt
or aJNull
into aOption[Int]
, it is possible it can be done in json4s directly.Which can be used as: