I am implementing this class User.scala
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 the reads: method the override is read in the Read type attribute (json: play.api.libs.json.JsValue) play.api.libs.json.JsResult [models.User];
read method has an incompatible type
I do not want to use the case class (or the problem will be solved) Can someone give me a hint about what to do?
Thanks.
source share