암시 적 Json이 다음과 같이 읽고 씁니다.
implicit val userJsonWrites = new Writes[User] {
override def writes(user: User): JsValue = Json.obj(
idKey -> Json.toJson(user._id),
firstNameKey -> Json.toJson(user.firstName),
lastNameKey -> Json.toJson(user.lastName),
emailKey -> Json.toJson(user.email),
//passKey -> Json.toJson(user.pass),
addressKey -> Json.toJson(user.address),
createDateKey -> Json.toJson(user.createDate),
activateDateKey -> Json.toJson(user.activateDate),
isUserActivatedKey -> Json.toJson(user.isUserActivated),
verificationDateKey -> Json.toJson(user.verificationDate)
)
}
implicit val userJsonReads = new Reads[User] {
override def reads(json: JsValue): JsResult[User] = {
val user = User(
_id = (json \ idKey).as[Option[String]],
firstName = (json \ firstNameKey).as[String],
lastName = (json \ lastNameKey).as[String],
email = (json \ emailKey).as[String],
pass = (json \ passKey).as[String],
address = (json \ addressKey).as[Address],
createDate = (json \ createDateKey).as[DateTime],
activateDate = (json \ activateDateKey).as[Option[DateTime]],
verificationDate = (json \ verificationDateKey).as[Option[DateTime]],
isUserActivated = (json \ isUserActivatedKey).as[Boolean]
)
JsSuccess(user)
}
}
컴파일 할 때 다음과 같은 오류가 발생합니다.
Error:(84, 32) not enough arguments for method as: (implicit fjs: play.api.libs.json.Reads[Option[String]])Option[String].
Unspecified value parameter fjs.
_id = (json \ idKey).as[Option[String]],
^
Error:(84, 32) No Json deserializer found for type Option[String]. Try to implement an implicit Reads or Format for this type.
_id = (json \ idKey).as[Option[String]],
^
내 사용자 개체는 다음과 같습니다.
case class User(
_id: Option[String],
createDate: DateTime,
activateDate: Option[DateTime],
verificationDate: Option[DateTime],
email: String,
pass: String,
firstName: String,
lastName: String,
isUserActivated: Boolean,
address: Address
)
_id는 실제로 내가 옵션으로 가지고 있어야하는 MongoDB의 ObjectId입니다!
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다