score:0

Accepted answer

fjs.reads(JsNull) returns JsResult[T] which is then wrapped into Option by opt

so there are couple of issues with this code:

  • return type should be Option[JsResult[T]]
  • JsUndefined is not a subclass of JsResult, so you can't use it in match
  • compiler error message is cryptic indeed, would you mind submitting an issue to scala tracker?

here is the code I think you were trying to implement

  case class Account()

  case class BasicAuthRequest[A](account: Account, request: Request[A]) extends WrappedRequest(request) {
    def asOpt[T](implicit fjs: Reads[T]): Option[T] =
      scala.util.control.Exception.catching(classOf[RuntimeException]).opt(fjs.reads(JsNull)).flatMap(_.asOpt)
  }

Related Query

More Query from same tag