Skip to content
This repository was 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

@domdorn

Description

@domdorn
    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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions