Why am I getting “Application does not accept parameters” and how can I fix it?

@TravisBrown helped me yesterday with an implicit function that returned Writes [T] , in which I worked fine, but today I tried to adapt it for another example and received an error on the last line ("Application does not accept parameters"). What am I doing wrong?

Please ignore the methods toString, they are just there for debugging.

import play.api.libs.json._
import play.api.libs.functional.syntax._

sealed trait PressureUnit
case object HectoPascalsUnit extends PressureUnit  { override def toString(): String = "(HectoPascalsUnit)" }
case object InchesMercuryUnit extends PressureUnit { override def toString(): String = "(InchesMercuryUnit)" }

case class Pressure(value: Float, unit: PressureUnit)

class SeaLevelPressure(override val value: Float, override val unit: PressureUnit) extends Pressure(value, unit) {
  override def toString(): String = "(SeaLevelPressure value:"+value+" unit:"+unit+")"
}
class StationPressure(override val value: Float, override val unit: PressureUnit) extends Pressure(value, unit) {
  override def toString(): String = "(StationPressure value:"+value+" unit:"+unit+")"
}

object Pressure {
  implicit val pressureWrites: Writes[Pressure] = (
    (__ \ 'value).write[Int] and
      (__ \ 'unit).write[String].contramap[PressureUnit] {
        case HectoPascalsUnit => "hPa"
        case InchesMercuryUnit => "INS"
      }
    )(unlift(Pressure.unapply))  // Error: Application does not take parameters
}
+4
source share
1 answer

I get it. I needed to change this:

(__ \ 'value.write[Int] and

:

(__ \ 'value.write[Float] and

Sorry to bother you!

+4
source

All Articles