I know that has been asked already, but I can't seem to find an answer. Here is my code :
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import spray.json.DefaultJsonProtocol
final case class Client(clientId:Int, clientName:String, platformIds:Int, host:String, password:String)
object ClientJson extends DefaultJsonProtocol with SprayJsonSupport {
implicit val clientFormat = jsonFormat5(Client)
}
class HTTPListenerActor extends Actor with ImplicitMaterializer with RoadMap {
implicit val conf = context.system.settings.config
implicit val system = context.system
implicit val ec = context.dispatcher
Await.result(Http().bindAndHandle(roads, "interface", 8080), Duration.Inf)
override def receive:Receive = Actor.emptyBehavior
}
trait RoadMap extends Directives {
val roads: Route = path("client"/IntNumber) { id =>
import ClientJson._
post {
entity(as[Client]) { c => complete {c} }
}
}
}
This code generates error
[ant:scalac] /Users/smalov/Workspace/api-service/src/main/scala/com/acheron/HTTPListenerActor.scala:51: error: could not find implicit value for parameter um: akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller[com.acheron.Client]
[ant:scalac] entity(as[Client]) { c =>
Now the most common cause for this kind of error is forgetting to import marshalling implicit into the scope near the roads
definition, however, I did not forget this. Another reason could be that I have implicit FlowMaterializer
in scope instead of ActorMaterializer
, but ImplictMaterializer
trait takes care of this.
Anything else I could be missing ?
I'm using Scala 2.11.7, Akka 2.3.11, akka-http 1.0, spray-json 1.3.2
I too got the same error and it resolved after importing
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
May be this will help
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