score:2

Accepted answer

this occurs because play json's writes & reads macros share a common implementation. within this implementation the type a provided to json.writes[a] is inspected for it's apply method, which in turn is used to generate the apply for the writes instance.

as an alternative to using the 'writes' macro, you can create just roll your own write[citysuggestion] like this:

import play.api.libs.json._
import play.api.libs.functional.syntax._

implicit val citysuggestionwrites: writes[citysuggestion] = (
  (jspath \ "name").write[string] and
  (jspath \ "locationid").write[string] and
  (jspath \ "locationkind").write[string]
)(unlift(citysuggestion.unapply))

Related Query

More Query from same tag