Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

PlayJson: ToResponseMarshaller does not work when a Format[A] is given instead a Writes[A] #659

Open
domdorn opened this issue Nov 25, 2021 · 0 comments

Comments

@domdorn
Copy link

domdorn commented Nov 25, 2021

    implicit val responseFormat: Format[Response] = (
      (JsPath \ "correlationId").format[CorrelationId] ~
        (JsPath \ "items").format[List[ResponseItem]]
    )(Response.apply, unlift(Response.unapply))

has to be changed to

    implicit val responseWrites: Writes[Response] = (
      (JsPath \ "correlationId").write[CorrelationId] ~
        (JsPath \ "items").write[List[ResponseItem]]
    )(unlift(Response.unapply))
    
    implicit val responseReads: Reads[Response] = (
      (JsPath \ "correlationId").read[CorrelationId] ~
        (JsPath \ "items").read[List[ResponseItem]]
    )(Response.apply _)

to make an error like this go away:

[error] /Users/domdorn/acme/masterdata-service/masterdata-web/src/main/scala/com/acme/masterdata/web/controllers/manager/GetScenarioListController.scala:116:87: type mismatch;
[error]  found   : [T](status: akka.http.scaladsl.model.StatusCode, headers: Seq[akka.http.scaladsl.model.HttpHeader], v: => T)(implicit m: akka.http.scaladsl.marshalling.ToEntityMarshaller[T]): akka.http.scaladsl.server.StandardRoute <and> [T](status: akka.http.scaladsl.model.StatusCode, v: => T)(implicit m: akka.http.scaladsl.marshalling.ToEntityMarshaller[T]): akka.http.scaladsl.server.StandardRoute <and> (m: => akka.http.scaladsl.marshalling.ToResponseMarshallable): akka.http.scaladsl.server.StandardRoute
[error]  required: com.acme.masterdata.web.controllers.manager.GetScenarioListController.Response => akka.http.scaladsl.server.Route
[error]     (which expands to)  com.acme.masterdata.web.controllers.manager.GetScenarioListController.Response => (akka.http.scaladsl.server.RequestContext => scala.concurrent.Future[akka.http.scaladsl.server.RouteResult])
[error]       ZIODirectives.zioEffect(callService(correlationId, userId, includeArchived).map(complete(_)))

reason for this (as far as I can tell) is that in
de.heikoseeberger.akkahttpplayjson.PlayJsonSupport we'd need an implicit conversion from Format[A] to Writes[A] or at least the same methods that take a Format[A]

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant