How to Marshall a Future[Option[Foo]] class to JSON in AKKA-HTTP How to Marshall a Future[Option[Foo]] class to JSON in AKKA-HTTP json json

How to Marshall a Future[Option[Foo]] class to JSON in AKKA-HTTP


Looking at: http://doc.akka.io/docs/akka-stream-and-http-experimental/2.0.3/scala/http/common/json-support.html and adding the following code:

import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupportimport spray.json._trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol {  implicit val userFormat = jsonFormat2(Foo)}


This wil deal with your Future problem. And will work if you hava something which converts Option[com.cassandra.phantom.modeling.MiTabla.User]] to a ToResponseMarshallable

val route = pathSingleSlash {    get { ctx =>      ctx.complete(getById())    }}