I am trying to make a generic Writer to get me the String representation of a json with Play Json. What I've got till now is
import com.twitter.finatra.http.Controller
import play.api.libs.json.{Json, Writes}
trait MyController extends Controller {
def handle(request: AnyRef) =
response
.ok
.json(createJsonResponse(manage(request)))
.toFuture
def manage[T : Writes](request: AnyRef): T
// There should be an implicit Writes[T] in scope
def createJsonResponse[T : Writes](data: T) = Json.stringify(Json.toJson[T](data))
}
I have case class TotalsForResponse(issuer: String, total: Int)
defined and
object JsonFormatters {
implicit val totalsForResponseWrites = Json.format[TotalsForResponse]
}
This should provide me at RunTime with an implicit Writes[T] in scope. IN one of my controllers I have
def manage[T : Writes](request: AnyRef) = request match {
case TotalInvestorsForRequest(issuer) =>
TotalsForResponse(issuer,
TitleSectionDBHandler.totalInvestorsFor(issuer))
.asInstanceOf[T]
}
which results in diverging implicit expansion for type play.api.libs.json.Writes[Nothing]
at runtime. This was taken from this example which I couldn't get it to work. Any ideas?
Aucun commentaire:
Enregistrer un commentaire