I am using akka-http
and writing an Unmarhsaller
for one of my classes. What I am trying to do is to get the body of the POST request as a String
so I can create my object with it :
case class MyClass(geom: String)
implicit def fromRequestUnmarshaller = Unmarshaller[HttpRequest, MyClass]({implicit ec: ExecutionContext =>
req: HttpRequest => Future(MyClass(req.entity.asInstanceOf[HttpEntity.Strict].data.map(_.toChar).mkString))
})
It seems like a very complicated line of code just to get the body as a String
. Plus, I am doing a very ugly asInstanceOf[HttpEntity.Strict]
just because I figured the HttpRequest
was of this type while debugging.
My question: is there a simpler/cleaner way to achieve my goal ?
Thanks a lot :)