Im new to acala and akka, so the question may be a little silly.
I have a class:
case class Foo(colUNO: String, colDOS: Long)
I have a funtion:
getById() : Future[Option[Foo]]
And I am trying to use it in the akka-http route
def main(args: Array[String]) {
implicit val actorSystem = ActorSystem("system")
implicit val actorMaterializer = ActorMaterializer()
val route = pathSingleSlash {
get {
complete {
val fut = getById()
}
}
}
Http().bindAndHandle(route,"localhost",8080)
println("server started at 8080")
}
But the error says:
Error:(39, 20) type mismatch; found : scala.concurrent.Future[Option[com.cassandra.phantom.modeling.MiTabla.User]] required: akka.http.scaladsl.marshalling.ToResponseMarshallable getById(id)
What I have to do to return a Json of Foo?
Thanks!!
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.SprayJsonSupport
import spray.json._
trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
implicit val userFormat = jsonFormat2(Foo)
}
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.SprayJsonSupport
import spray.json._
trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
implicit val userFormat = jsonFormat2(Foo)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With