Scala/Play: JSON serialization issue Scala/Play: JSON serialization issue json json

Scala/Play: JSON serialization issue


Short answer:

Just add:

implicit val filterWrites = Json.writes[Filter]

Longer answer:

If you look at the definition of Json.toJson, you will see that its complete signature is:

def toJson[T](o: T)(implicit tjs: Writes[T]): JsValue = tjs.writes(o)

Writes[T] knows how to take a T and transform it to a JsValue. You will need to have an implicit Writes[Filter] around that knows how to serialize your Filter instance. The good news is that Play's JSON library comes with a macro that can instantiate those Writes[_] for you, so you don't have to write boring code that transforms your case class's fields into JSON values. To invoke this macro and have its value picked up by implicit search add the line above to your scope.