Could not find implicit value for marshaller parameter: spray.httpx.marshalling.ToResponseMarshaller

I use

val akkaV = "2.2.3" val sprayV = "1.2.0" Seq( "io.spray" % "spray-can" % sprayV, "io.spray" % "spray-routing" % sprayV, "io.spray" %% "spray-json" % "1.2.5", "io.spray" % "spray-testkit" % sprayV, "com.typesafe.akka" %% "akka-actor" % akkaV, "com.typesafe.akka" %% "akka-testkit" % akkaV, 

And getting this error:

could not find the implicit value of the marshaller parameter: spray.httpx.marshalling.ToResponseMarshaller [List [org.bwi.models.Cluster]]

using this code:

 object JsonImplicits extends DefaultJsonProtocol { val impCluster = jsonFormat2(Cluster) } trait ToolsService extends HttpService with spray.httpx.SprayJsonSupport { val myRoute = { import JsonImplicits._ path("") { get { getFromResource("tools.html") } } ~ pathPrefix("css") { get { getFromResourceDirectory("css") } } ~ pathPrefix("fonts") { get { getFromResourceDirectory("fonts") } } ~ pathPrefix("js") { get { getFromResourceDirectory("js") } } ~ path("clusters") { get { complete { val result: List[Cluster] = List(Cluster("1", "1 d"), Cluster("2", "2 d"), Cluster("3", "3 d")) result //***** ERROR OCCURS HERE ***** } } } } 

}

I tried a suggestion on this , but it didnโ€™t work, same error.

I canโ€™t understand what implied I need to import. Any help would be appreciated.

+3
scala spray
source share
1 answer

You need to make sure that the implicit JsonFormat for the Cluster type is in scope, so that SprayJsonSupport knows how to march this type. In doing so, you should automatically get List[Cluster] marshaling support from standard formats.

In the published code, val impCluster = jsonFormat2(Cluster) defines JsonFormat , but it is not marked as implicit , so the type class cannot be implicitly resolved. Change it to

 implicit val impCluster = jsonFormat2(Cluster) 

should fix the problem.

+5
source

All Articles