I had an Main app with the following structure:
implicit val orgs: RootJsonFormat[GHOrg] = jsonFormat3(GHOrg)
implicit val users: RootJsonFormat[GHUser] = jsonFormat2(GHUser)
implicit val repos: RootJsonFormat[GHRepo] = jsonFormat3(GHRepo)
case class GHUser(login: String, contributions: Option[Int] = None)
case class GHRepo(name: String, owner: GHUser, contributors_url: String)
case class GHOrg(name: String, repos_url: String, members_url: String)
At some point I do
Unmarshal(e).to[List[GHRepo]]
And everything works, however, I have been doing a little bit of code cleaning and I have moved the three case classes above to a different package, and now I am getting title's error. I have tried this suggestion (spray-json error: could not find implicit value for parameter um) but does not work.
Here is how the current code (Not compiling):
import akka.actor.ActorSystem
import akka.http.javadsl.model.StatusCodes
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
import akka.http.scaladsl.model._
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.stream.ActorMaterializer
import com.elbauldelprogramador.domain.{GHOrg, GHRepo, GHUser}
import org.slf4j.LoggerFactory
import spray.json.DefaultJsonProtocol._
import spray.json.RootJsonFormat
object Main extends App {
implicit val system: ActorSystem = ActorSystem()
implicit val materializer: ActorMaterializer = ActorMaterializer()
implicit val executionContext: ExecutionContextExecutor = system.dispatcher
implicit val orgs: RootJsonFormat[GHOrg] = jsonFormat3(GHOrg)
implicit val users: RootJsonFormat[GHUser] = jsonFormat2(GHUser)
implicit val repos: RootJsonFormat[GHRepo] = jsonFormat3(GHRepo)
// ....
Unmarshal(e).to[List[GHRepo]] // Error
// ....
}
Here is the full error:
could not find implicit value for parameter um: akka.http.scaladsl.unmarshalling.Unmarshaller[akka.http.scaladsl.model.ResponseEntity,List[com.elbauldelprogramador.domain.GHUser]] [error] val users = Unmarshal(e).to[List[GHUser]] [error] ^
jsonBody.parseJson.convertTo[List[GHRepo]]
. – Mikhail IonkinResponseEntity
– ElBaulPMain
for test. And what isum
? PS: I found it isimplicit um: FromRequestUnmarshaller[T]
– Mikhail IonkinList[GHRepo]
with use different packages for case classes. I use"""[{"owner":{"login": "sd"}}]""".parseJson.convertTo[List[GHRepo]]
and gotList(GHRepo(GHUser(sd)))
(I remove 2 fields from case classes to simplify). – Mikhail Ionkin