I've yet to test this out, but it compiles. Hope I'm on the right track.

trait APIStatusMarshallers {


  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

    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

  }

}

On Fri, Sep 2, 2016 at 1:01 PM, Richard Rodseth <rrods...@gmail.com> wrote:

> I'm guessing the errorMarshaller and statusMarshaller shown (which use
> compose) need to be recast according to
>
> http://doc.akka.io/docs/akka/2.4.9/scala/http/common/
> marshalling.html#Deriving_Marshallers
>
> But that paragraph of documentation could really use an example.
>
>
> On Thu, Sep 1, 2016 at 3:19 PM, Richard Rodseth <rrods...@gmail.com>
> wrote:
>
>> I'm struggling to convert the following response marshaller.
>> ToResponseMarshaller is a trait and object in Spray, and Marshaller takes
>> one type parameter.
>>
>> I've read the docs, and am stumped. Can anyone provide further guidance?
>>
>> // See https://bitbucket.org/binarycamp/spray-contrib/src
>>
>>
>> trait APIStatusMarshallers {
>>
>>
>>     implicit def errorMarshaller[T](implicit translator: ErrorTranslator[
>> T],
>>
>>                                   statusCodeMapper:
>> ErrorToStatusCodeMapper,
>>
>>                                   m: Marshaller[T]): ToResponseMarshaller
>> [APIError] =
>>
>>     ToResponseMarshaller.fromStatusCodeAndHeadersAndT.compose {
>>
>>       error => (statusCodeMapper.orElse(ErrorToStatusCodeMapper.Default)(
>> error), DefaultHttpHeaders.NoCacheHeaders,translator(error))
>>
>>     }
>>
>>
>>
>>     implicit def statusMarshaller[T](implicit m: Marshaller[T]):
>> ToResponseMarshaller[PimpedResult[(StatusCode, T)]] = {
>>
>>     ToResponseMarshaller.fromStatusCodeAndHeadersAndT.compose {
>>
>>       pimpedResult => pimpedResult.result match {
>>
>>         case Right(response) => (response._1, DefaultHttpHeaders.
>> NoCacheHeaders, response._2)
>>
>>         case _ => throw new RuntimeException("StatusMarshaller got
>> invalid PimpedResult")
>>
>>       }
>>
>>     }
>>
>>   }
>>
>> }
>>
>
>

-- 
>>>>>>>>>>      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+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to