当创建类型不匹配错误播放2.1读取(type mismatch error when creatin

2019-08-19 08:36发布

我一直在玩这个了好几个小时。 我一直在努力创造一个读不同的方法,我只是完全难住了。

我在Play 2.1.0Scala 2.10.1

错误:

type mismatch; found : models.Registration.type required: play.api.libs.json.Reads[?]

码:

package models

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

case class Registration(
        user: (String,String,String,String,String,String)
)

object RegistrationHelper {
    implicit val regReads: Reads[Registration] = (
      (__ \ "user").read(
        (__ \ "id").read[String] and
        (__ \ "username").read[String] and
        (__ \ "first_name").read[String] and
        (__ \ "last_name").read[String] and
        (__ \ "email_address").read[String] and
        (__ \ "user_avatar").read[String]
        tupled
      )
    )(Registration) //!!ERROR ON THIS LINE
}

JSON:

{
  user: {
    id: "35fc8ba5-56c3-4ebe-9a21-489a1a207d2e",
    username: "flastname",
    first_name: "Firstname",
    last_name: "Lastname",
    email_address: "foo@bar.com",
    user_avatar: "http://blog.ideeinc.com/wp-content/uploads/2010/04/tineye-robot.jpg"
  }
}

Answer 1:

这应该工作:

implicit val regReads: Reads[Registration] = (__ \ "user").read(
    (__ \ "id").read[String] and
      (__ \ "username").read[String] and
      (__ \ "first_name").read[String] and
      (__ \ "last_name").read[String] and
      (__ \ "email_address").read[String] and
      (__ \ "user_avatar").read[String]
      tupled
  ) map Registration.apply _

见这以获取更多信息的问题。



文章来源: type mismatch error when creating Reads for Play 2.1