Knows Not Much
Knows Not Much

Reputation: 31576

Could not access type Unmarshaller in value akka.http.javadsl.unmarshalling

I am trying to write a simple Http client using Akka Http Client API. Towards this I have written the following code

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.unmarshalling._
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{Sink, Source}
import scala.concurrent.duration._
import scala.concurrent.{Await}
import akka.http.scaladsl.server.Directives
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import spray.json._

final case class Post(postId: Int, id: Int, name: String, email: String, body: String)

trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
   implicit val postFormat = jsonFormat5(Post.apply)
}

class AkkaHttpClient extends App with Directives with JsonSupport {
   implicit val system = ActorSystem("my-Actor")
   implicit val actorMaterializer = ActorMaterializer()
   implicit val executionContext = system.dispatcher
   val httpClient = Http().outgoingConnection(host="http://jsonplaceholder.typicode.com/")
   val flow = Source.single(HttpRequest(uri = Uri("/comments/1")))
      .via(httpClient)
      .mapAsync(1)(r => Unmarshal(r.entity).to[Post])
      .runWith(Sink.head)

   val results = Await.result(flow, 15 seconds)
   println(results)
}

My build.sbt file looks like

name := "Akka-Http-Client"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
   "com.typesafe.akka" %% "akka-http-experimental" % "2.4.9-RC1",
   "com.typesafe.akka" %% "akka-http-spray-json-experimental" % "2.4.9-RC1"
)

When I try to compile my code I get these errors

Error:scalac: missing or invalid dependency detected while loading class file 'Unmarshaller.class'.
Could not access type Unmarshaller in value akka.http.javadsl.unmarshalling,
because it (or its dependencies) are missing. Check your build definition for
missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
A full rebuild may help if 'Unmarshaller.class' was compiled against an incompatible version of akka.http.javadsl.unmarshalling.

Upvotes: 1

Views: 510

Answers (1)

Vladislav Rybin
Vladislav Rybin

Reputation: 36

I am having the same problem on 2.4.9-RC1, falling back to 2.4.8 solves the problem.

OR you could use this workaround described here: https://github.com/akka/akka/issues/21105

Upvotes: 2

Related Questions