I meet a problem while implementing Json Write for my case class that I use with squeryl and which extend KeyedEntity. It looks like this:
case class Order(fk_soc : Int, order_date: String, date_creation: Timestamp,fk_uther_author: Int, fk_statut : Int, tva : Option[Double], total_ht: Option[Double],total_ttc: Option[Double], note: Option[String]) extends KeyedEntity[Int] {
val id : Int = 0
val ref : String = ""
val date_modif : Option[Timestamp] = Some(new Timestamp(DateTime.now.getMillis))
}
And my Writes:
implicit val orderFormat : Writes[Order] = (
( __ \ 'fk_societe).write[Int] and
( __ \ 'order_date).write[String] and
( __ \ 'date_creation).write[Timestamp] and
( __ \ 'fk_user_author).write[Int] and
( __ \ 'fk_statut).write[Int] and
( __ \ 'tva).write[Option[Double]] and
( __ \ 'total_ht).write[Option[Double]] and
( __ \ 'total_ttc).write[Option[Double]] and
( __ \ 'note).write[Option[String]]
)(unlift(Order.unapply))
And it works fine except that i need include "id" field in my json but as it's in the body of my case class, it doesn't falls in to the generated value. So if I add "id" field to my Writes:
implicit val orderFormat : Writes[Order] = (
( __ \ 'id).write[Int] and
( __ \ 'fk_societe).write[Int] and
.......
It doesn't work as expected... How implement this Writes to include id field? I need a custom apply/unapply method? I stress that my case class is implemented so to works with squeryl KeyedEntity ( id in the body ...)