0
votes

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]

2

2 Answers

4
votes

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.

1
votes

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