创建Reads for Play 2.1时键入不匹配错误 [英] type mismatch error when creating Reads for Play 2.1
本文介绍了创建Reads for Play 2.1时键入不匹配错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经玩了几个小时了.我一直在尝试使用不同的方法来创建读取,但是我完全陷入了困境.
I have been playing with this for hours. I have been trying different methods of creating a read and I am just completely stumped.
我在Play 2.1.0
和Scala 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"
}
}
推荐答案
这应该有效:
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 _
请参见此问题以获取更多信息.
See this question for more information.
这篇关于创建Reads for Play 2.1时键入不匹配错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文