为什么我会得到;应用程序不接受参数“;在Play framework 2.3中使用JSON读取?

为什么我会得到;应用程序不接受参数“;在Play framework 2.3中使用JSON读取?,json,scala,validation,playframework-2.3,Json,Scala,Validation,Playframework 2.3,我想在Play framework 2.3x中为几个Scala模型类编写JSON验证。我使用JSON读取来按照说明()完成这项工作。但我得到了“应用程序不接受参数”错误,我不知道如何解决这个问题 这是我的密码 package models import play.api.libs.json._ import play.api.libs.json.Reads._ import play.api.libs.functional.syntax._ import reactivemongo.bson.

我想在Play framework 2.3x中为几个Scala模型类编写JSON验证。我使用JSON读取来按照说明()完成这项工作。但我得到了“应用程序不接受参数”错误,我不知道如何解决这个问题

这是我的密码

package models

import play.api.libs.json._
import play.api.libs.json.Reads._
import play.api.libs.functional.syntax._
import reactivemongo.bson.BSONObjectID
import java.util.Date

case class ArtifactModel(
                          _id: BSONObjectID,
                          name: String,
                          createdAt: Date,
                          updatedAt: Date,
                          attributes: List[AttributeModel],
                          stateModels: List[StateModel])

case class AttributeModel(
                           name: String,
                           comment: String)

case class StateModel(
                       name: String,
                       comment: String)

object ArtifactModel {
  implicit val artifactModelReads: Reads[ArtifactModel] = (
      (__ \ "_id").readNullable[String] ~
      (__ \ "name").read[String] ~
      (__ \ "createdAt").readNullable[Long] ~
      (__ \ "updatedAt").readNullable[Long] ~
      (__ \ "attributes").read[List[AttributeModel]] ~
      (__ \ "stateModels").read[List[StateModel]]
    )(ArtifactModel) // here is the error: "Application does not take parameters"


  implicit val attributeModelReads: Reads[AttributeModel] = (
      (__ \ "name").read[String] ~
      (__ \ "comment").read[String]
    )(AttributeModel)

  implicit val stateModelReads: Reads[StateModel] = (
      (__ \ "name").read[String] ~
      (__ \ "comment").read[String]
    )(StateModel)
}

你能帮我吗?对于Scala/Play中JSON验证的任何解决方案或建议,我们将不胜感激

Reads对象的类型与apply方法的类型不同。例如,
readNullable[String]
results
Option[String]
,而不是
String
。对于
BSONObjectId
日期
也一样。这可以编译,但您可能需要使用一些映射:

  implicit val artifactModelReads: Reads[ArtifactModel] = (
(__ \ "_id").read[BSONObjectID] ~
  (__ \ "name").read[String] ~
  (__ \ "createdAt").read[Date] ~
  (__ \ "updatedAt").read[Date] ~
  (__ \ "attributes").read[List[AttributeModel]] ~
  (__ \ "stateModels").read[List[StateModel]]
)(ArtifactModel.apply _)
您可以在读取后,像这样(
CONVERT\u TO\u DATE
是虚构的):


我已经试过了,但对我不起作用。错误是一样的。我很困惑。
  implicit val artifactModelReads: Reads[ArtifactModel] = (
(__ \ "_id").read[BSONObjectID] ~
  (__ \ "name").read[String] ~
  (__ \ "createdAt").read[String].map( s=>CONVERT_TO_DATE(s) ) ~
  (__ \ "updatedAt").read[Date] ~
  (__ \ "attributes").read[List[AttributeModel]] ~
  (__ \ "stateModels").read[List[StateModel]]
)(ArtifactModel.apply _)