Reputation: 201
We have a json like the below
{
"-KULpL4Qrzt4z8Go": {
"dateTime": 1476778076353,
"partyName": "AMBA",
"partyId": "A101",
"points": {
"-KULr3tag86GlJSZp": {
"lat": 71.1426377,
"lon": 29.0803357,
"dtime": 1476778091998
},
"-KULr3v9zJA4NqLOf": {
"lat": 91.1426377,
"lon": 26.0803357,
"dtime":
}
}
}
}
I use play json (for Scala 2.10.6) and want to get the data into the models
case class JsonPlay(dateTime:String,partyName:String,partyId:String)
case class PointsPlay(lat:Double, lon:Double, dtime:Option[BigInt])
But my first Read itself throws and exception, saying unable to find \ dateTime etc.
implicit val baseReads: Reads[JsonPlay] = (
(JsPath \ "dateTime").read[String] and
(JsPath \ "partyName").read[String] and
(JsPath \ "partyId").read[String] and
)(JsonPlay.apply _)
Appreciate any pointers/help in getting this work. Thanks.
-Venkiram
Upvotes: 0
Views: 59
Reputation: 7591
dateTime
is a long in this case. It should be:
case class JsonPlay(dateTime: Long, partyName: String, partyId: String)
implicit val baseReads: Reads[JsonPlay] = (
(JsPath \ "dateTime").read[Long] and
(JsPath \ "partyName").read[String] and
(JsPath \ "partyId").read[String] and
)(JsonPlay.apply _)
Upvotes: 1