我想创建一个自定义操作,它可以消除编写这样的操作的样板:
Action[MyClass](BodyParsers.parse.json[MyClass]) { req => ...
但是,我一直遇到类定义错误。这是我最成功的尝试:
class JsonAction[A: Reads] extends ActionBuilder[Request] {
def hardcodedJson[A: Reads](action: Action[A]) =
Action.async(BodyParsers.parse.json[A]) { request => action(request) }
def invokeBlock[A: Reads](request: Request[A], block: (Request[A]) => Future[Result]) = {
block(request)
}
override def composeAction[A: Reads](action: Action[A]) = hardcodedJson(action)
}
但我收到以下错误:method composeAction overrides nothing.
如果我改成composeAction[A: Reads]
它composeAction[A]
告诉我没有 A 类型的 Json 序列化器。
还有其他方法可以定义此自定义操作吗?