Reputation: 841
I'm starting to play with Scala and while doing some examples from play framework page, I've found problem which I can't resolve. I'm pretty new in Scala so I please to be forgiving.
Why this one compiles without errors:
case class Location(lat: Double, long: Double)
implicit val locationReads: Reads[Location] = (
(JsPath \ "lat").read[Double] and
(JsPath \ "long").read[Double]
)(Location.apply _)
but this one won't compile:
case class Location(lat: Double)
implicit val locationReads: Reads[Location] = (
(JsPath \ "lat").read[Double]
)(Location.apply _)
and displaying error:
overloaded method value read with alternatives: [error] (t: Double)play.api.libs.json.Reads[Double] [error] (implicit r: play.api.libs.json.Reads[Double])play.api.libs.json.Reads[Double] [error] cannot be applied to (Double => biz.JsonProtocol.Location) [error] (JsPath \ "lat").read[Double]
Upvotes: 0
Views: 1525
Reputation: 4427
It turns out there are some limitations when using JSON combinators with single-field case classes in play versions <= 2.1 (it has been marked as solved already). See this question for a possible solution.
Upvotes: 4
Reputation: 52
Looks like you can't have a biz.JsonProtocol.Location with only a latitude...that's why your exemplar with lat AND long works but just lat won't compile
Upvotes: 1