I have created simple trait which should convert models into json:
trait Protocols extends SprayJsonSupport with DefaultJsonProtocol {
implicit val travelFormat = jsonFormat4(Travel)
}
I have a Travel model which looks like:
case class Travel(id: Option[Long] = None,
startDate: DateTime,
endDate: DateTime,
name: String,
description: String,
amount: BigDecimal)
But the problem is (as I found out) in DateTime class. In this code I get a compiler error on jsonFormat4 method:
Type mismatch, expected: (NotInferedP1, NotInferedP2, NotInferedP3, NotInferedP4) => NotInferedT, actual: (Option[Long], DateTime, DateTime, String, String, BigDecimal) => Travel
When I remove all DateTime fields it works well. But in my case, I need this fields. So how shoud I fix it? I tried give a default parameter to them, but it also did not work.
Could you try writing a custom formatter like this for example:
I'm using the play-json library in the above example!