I'm using akka-http 1.0.-RC4.
How can I extract Future[T] value in unmarshaller without blocking ?
I extended ScalaXmlSupport you created to support unmarshalling http requests using Unmarshaller[NodeSeq, T] unmarshallers by adding this
implicit def xmlUnmarshallerConverter[T](marshaller: Unmarshaller[NodeSeq, T])(implicit mat: Materializer): FromEntityUnmarshaller[T] =
xmlUnmarshaller(marshaller, mat)
implicit def xmlUnmarshaller[T](implicit marshaller: Unmarshaller[NodeSeq, T], mat: Materializer): FromEntityUnmarshaller[T] = {
implicit val exec = mat.executionContext
defaultNodeSeqUnmarshaller.map(v => {
val future = marshaller(v)(mat.executionContext)
val result = Await.result(future, Duration(10, TimeUnit.SECONDS))
result
})
}
The only problem is that prototype of Unmarshaller.apply is this
def apply[A, B](f: ExecutionContext ⇒ A ⇒ Future[B]): Unmarshaller[A, B]
It requires me to returns Future which I do by creating unmarshallers of model classes like
implicit val articleBodyUnmarshaller = Unmarshaller[NodeSeq, ArticleBody] { xml =>
Future(ArticleBody(xml.toString()))
}
But I can't use it in xmlUnmarshaller : FromEntityUnmarshaller[T] because it requires me to return concrete object which forces me to do ugly blocking
How should I write it properly ?