Hi,
I have a question regarding custom marshallers and how to apply them in routes.
My goal is to respond with JSON representations of person objects, using a
custom media type 'application/vnd.foo.person+json’.
I have a case class and implicit spray-json formats
case class Person(firstname:String, surname:String)
I also have written a media type and a marshaller:
val m = MediaType.custom("application/vnd.foo.person+json",
MediaType.Encoding.Fixed(HttpCharsets.`UTF-8`))
implicit def PersonMarshaller[T](implicit writer: RootJsonWriter[T], printer:
JsonPrinter = PrettyPrinter): ToEntityMarshaller[Person] =
Marshaller.StringMarshaller.wrap(ContentType(m))(p => printer.apply(p.toJson))
And I have the following route where I just cannot figure out the correct
directive to have akka-http apply the implicit marshaller
def status(statusActor: ActorRef) = {
path("status") {
get {
complete {
val f:Future[Person] = …. obtain future person object from some
foo.findPerson(…)
f.map(p =>
? <———————— what to do here?
)
}
}
}
}
Can anyone enlighten me?
I tried with
f.map(p => HttpResponse(entity = HttpEntity(m, p)))
but HttpEntity does not seem to be the place to hand the ‘domain object’ to
I also tried
HttpResponse(entity = p)
assuming the marshaller would be used to turn Person into Entity but that
doesn’t compile either
Jan
--
>>>>>>>>>> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.