Reputation: 3828
Is it possible to write additional property unavailable in case class constructor?
case class Task(var name:String, var counter:Int) extends Entity
by extending by Entity case class have also id property
implicit val task = (
(__ \ 'name).write[String] and
(__ \ 'counter).write[Int] and
(__ \ 'id).write[String] <==== ???
)(unlift(Task.unapply))
How can I add this property?
Upvotes: 1
Views: 33
Reputation: 23871
You can define your writes like this:
implicit val writer = new Writes[Task] {
def writes(t: Task): JsValue = {
Json.obj("name" -> t.name,
"counter" -> t.counter,
"id" -> t.getIdFromSomewhere) //here's the thing you want
}
}
Upvotes: 1