您好我在使用Play框架和表单(根据https://tools.ietf.org/html/rfc6902)实现补丁操作时遇到了一些麻烦。我们的想法是在补丁操作上进行模式匹配,以确定要采取的操作。到目前为止,我要做的事情是:
val myForm = Form(
tuple(
"op" -> text.verifying(List("replace", "add").contains(_)),
"path" -> text.verifying(List("/X", "/Y").contains(_)),
"value" -> of[AnyRef] //does not compile :'(
)
)
导致以下错误:"无法找到AnyRef的Formatter类型类。"
我如何解决这个问题,知道我的值字段可以是不同的类型,具体取决于目标子资源?
答案 0 :(得分:1)
我最终没有使用Play表单,而是使用基本读者,执行以下操作:
1. 10000 pushes done at :710.310000000005 msecs
2. 10000 pushes done at :1831.4599999999991 msecs
3. 10000 pushes done at :3018.199999999997 msecs
4. 10000 pushes done at :4113.779999999999 msecs
5. 10000 pushes done at :5144.470000000008 msecs
6. 10000 pushes done at :6588.179999999993 msecs
7. 10000 pushes done at :7860.005000000005 msecs
8. 10000 pushes done at :8727.050000000003 msecs
9. 10000 pushes done at :9795.709999999992 msecs
10. 10000 pushes done at :10866.055000000008 msecs
ringu is filled with 100000 random characters
Last concatenation took 1.0999999999912689 msecs
并在我的控制器中
case class PatchOperation(operation: String, path: String, value: JsValue)
implicit val patchOperationReads: Reads[PatchOperation] = (
(JsPath \ "op").read[String] and
(JsPath \ "path").read[String] and
(JsPath \ "value").read[JsValue]
) (PatchOperation.apply _)