Debugging marshalling implicits

98 views
Skip to first unread message

Richard Rodseth

unread,
Sep 7, 2016, 11:43:14 PM9/7/16
to akka...@googlegroups.com
Can anyone help me with this please?
I have the following in my route:

val result = (requestHandler ? RequestHandler.AskForStatus).mapTo[PimpedResult[(StatusCode, Result[StatusDTO])]]

onSuccess(result) {
  case _ => complete(result)
}

The mapTo is really just to assist my debugging. The result could be a Result[StatusDTO] or a PimpedResult.
Anyway, I get the following error on the complete call:

type mismatch; found : scala.concurrent.Future[PimpedResult[(akka.http.scaladsl.model.StatusCode, Result[StatusDTO])]] (which expands to) scala.concurrent.Future[PimpedResult[(akka.http.scaladsl.model.StatusCode, scala.util.Either[APIError,StatusDTO])]] required: akka.http.scaladsl.marshalling.ToResponseMarshallable

I added the following after the mapTo:

val prm = implicitly[Future[PimpedResult[(StatusCode, Result[StatusDTO])]] => ToResponseMarshallable]

and that line gets this error:

Multiple markers at this line:

not enough arguments for method implicitly: (implicit e: scala.concurrent.Future[PimpedResult[(akka.http.scaladsl.model.StatusCode, Result[StatusDTO])]] ⇒ akka.http.scaladsl.marshalling.ToResponseMarshallable)scala.concurrent.Future[PimpedResult[(akka.http.scaladsl.model.StatusCode, Result[StatusDTO])]] ⇒ akka.http.scaladsl.marshalling.ToResponseMarshallable. Unspecified value parameter e.
No implicit view available from scala.concurrent.Future[PimpedResult[(akka.http.scaladsl.model.StatusCode, Result[StatusDTO])]] ⇒ akka.http.scaladsl.marshalling.ToResponseMarshallable.

Here is the custom marshaller. I know it's in scope because the errorMarshaller works in the case where the response is Result[StatusDTO] rather than PimpedResult

trait APICustomMarshallers {

  implicit def errorMarshaller[T](
implicit translator: ErrorTranslator[T],
statusCodeMapper: ErrorToStatusCodeMapper,
m: ToEntityMarshaller[T]): ToResponseMarshaller[APIError] = {

    val base = PredefinedToResponseMarshallers.fromStatusCodeAndHeadersAndValue
    val result = base.compose {
      error: APIError => (statusCodeMapper.orElse(ErrorToStatusCodeMapper.Default)(error), DefaultHttpHeaders.NoCacheHeaders, translator(error))
    }
    result
  }

  implicit def statusMarshaller[T](implicit m: ToEntityMarshaller[T]): ToResponseMarshaller[PimpedResult[(StatusCode, T)]] = {
    val base = PredefinedToResponseMarshallers.fromStatusCodeAndHeadersAndValue // Needs the entity marshaller
    val result = base.compose {
      pimpedResult: PimpedResult[(StatusCode, T)] =>
        pimpedResult.result match {
          case Right(response) => (response._1, DefaultHttpHeaders.NoCacheHeaders, response._2)
          case _               => throw new RuntimeException("StatusMarshaller got invalid PimpedResult")
        }
    }
    result
  }
}

Thanks for any help.




Richard Rodseth

unread,
Sep 13, 2016, 10:26:55 AM9/13/16
to akka...@googlegroups.com
Bump.

Is this the right way to debug the missing conversion?
val prm = implicitly[Future[PimpedResult[(StatusCode, Result[StatusDTO])]] => ToResponseMarshallable]

Johannes Rudolph

unread,
Sep 20, 2016, 6:18:06 AM9/20/16
to Akka User List
Hi,


On Tuesday, September 13, 2016 at 4:26:55 PM UTC+2, rrodseth wrote:
> Is this the right way to debug the missing conversion?
> val prm = implicitly[Future[PimpedResult[(StatusCode, Result[StatusDTO])]] => ToResponseMarshallable]


Try

implicitly[ToResponseMarshaller[Future[PimpedResult[(StatusCode, Result[StatusDTO])]]]


then


implicitly[ToResponseMarshaller[PimpedResult[(StatusCode, Result[StatusDTO])]]


then

implicitly[ToEntityMarshaller[Result[StatusDTO]]] // required by APICustomMarshallers.statusMarshaller

or just 

statusMarshaller[Result[StatusDTO]]]


and see which one still succeeds. Then you need to work back from the simple ones to the more complex types, trying to get those to work.

HTH
Johannes

Richard Rodseth

unread,
Sep 21, 2016, 12:10:52 AM9/21/16
to akka...@googlegroups.com
Thanks. It appears to be the absence of an Either marshaller ( Result[T] is an alias for Either[APIError,T] )
Is that something that was available in Spray, but not in Akka HTTP ?
I see this got merged:

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscribe@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages