I'm implementig this User.scala class
class User(var id : Long , var name : String) {
def createUser() = {}
def setName(nome : String) : String = {
this.name = nome
return name
}
def getName() : String = {
return name
}
}
object User {
implicit object userFormat extends Format[User] {
override def reads(json: JsValue): User = new
User(
(json \ "id").as[Long],
(json \ "name").as[String]
)
override def writes(s: User): JsValue = JsObject(Seq(
"id" -> JsString(s.id.toString),
"name" -> JsString(s.name)
))
}
}
But I get this Error when on reads method:
overriding method reads in trait Reads of type (json:play.api.libs.json.JsValue)play.api.libs.json.JsResult[models.User];
method reads has incompatible type
I don't want to use a case class (or the problem would be solved), Can anybody give me an Hint on what to do?
Thanks.
You should wrap the "User" object in a JsResult, in this case JsSuccess
JsSuccess(new User(...))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With