Since documentation is not ready I'll ask akka maintainers here.
Why akka-http Unmarshaler
returns Future[T]
instead of T
? Here is my goal. I want to unmarshal class from XML http response similarly how it's done for json. For example I'd like to write
Unmarshal(HttpResponse.entity).to[Person]
where case class and its unmarshaller looks like this
case class Person(name: String, age: Int)
implicit val personUnmarshaller = Unmarshaller[NodeSeq, Person] { _ => xml =>
Future(Person((xml \\ "name").text, (xml \\ "age").text.toInt))
}
It's not gonna compile with ScalaXmlSupport
supplied with 1.0-RC4 because Unmarshaller[ResponseEntity,Person]
is not available in the scope. So to trick it I wrote two implicit conversions
implicit def xmlUnmarshallerConverter[T](marsh: Unmarshaller[NodeSeq, T])(implicit mat: Materializer): FromEntityUnmarshaller[T] =
xmlUnmarshaller(marsh, mat)
implicit def xmlUnmarshaller[T](implicit marsh: Unmarshaller[NodeSeq, T], mat: Materializer): FromEntityUnmarshaller[T] =
defaultNodeSeqUnmarshaller.map(Unmarshal(_).to[T].value.get.get)
It works but I don't like ugly .value.get.get
. Is there more elegant way to implement this ?