I'm trying to retrieve a Stream[IO, Job]
from an http4s Response
, but the Scala compiler warns me that it cannot find any suitable Decoder
:
Cannot decode into a value of type fs2.Stream[IO,Job], because no EntityDecoder[[+A]IO[A], fs2.Stream[IO,Job]] instance could be found.
[error] retrieved <- response.as[fs2.Stream[IO, Job]]
The code that generates the above error is the following:
import io.circe.generic.auto._
import org.http4s.circe.CirceEntityCodec._
// Many other imports
"should return the stream of all jobs" in {
for {
response <- jobsRoutes.orNotFound.run(
Request(
method = Method.GET,
uri = uri"/jobs",
headers = Headers(Accept(MediaType.`text/event-stream`))
)
)
retrieved <- response.as[fs2.Stream[IO, Job]]
} yield {
response.status shouldBe Status.Ok
}
}
In the build.sbt
file, I have the following dependencies:
// Many other omitted dependencies
"org.http4s" %% "http4s-circe" % "0.23.14",
"io.circe" %% "circe-generic" % "0.14.2",
"io.circe" %% "circe-fs2" % "0.14.0",
The definition of the Job
entity is:
final case class Job(
id: UUID,
date: Long,
salaryLo: Option[Int],
salaryHi: Option[Int],
currency: Option[String],
location: String,
tags: List[String],
description: String,
localUrl: Option[String],
externalUrl: Option[String]
image: Option[String],
country: Option[String],
title: String,
company: String,
seniority: Option[String],
other: Option[String]
)
I cannot understand what's going on.