2
votes

I apologize if I'm missing something simple, but I'm trying to use Akka HTTP with Circe (using the akka-http-json Circe module). I'm trying to retrieve the results of a GET call in a ScalaTest which mixes in the ErrorAccumulatingCirceSupport trait. The call goes through successfully, but I'm unable to unmarshal the response...It's a pretty simple test, but I'm just not sure how to unmarshal the results into a list of domain objects, eg:

    Get("/path/to/getfoos").withHeaders(auth) ~> Route.seal(service.route) ~> check {
      import io.circe.generic.auto._
      status shouldEqual StatusCodes.OK
      contentType should ===(ContentTypes.`application/json`)
      val reports = responseAs[List[Foo]]
      reports.size shouldBe 1
   }

The error I'm getting is:

Could not unmarshal response to type 'scala.collection.immutable.List' for `responseAs` assertion: de.heikoseeberger.akkahttpcirce.ErrorAccumulatingCirceSupport$DecodingFailures: DecodingFailure at [0]: CNil

If anyone can point out what I'm dong wrong I would very much appreciate the help!

Thanks!

1
Can you share your Foo definition?Travis Brown
@TravisBrown : Foo is actually an ADT (case class subtype of a sealed trait) composed of other ADTs, though none are very complex. I was able to get it to work by getting the HttpEntity and using Unmarshal on it (I'll post the code below in case there's a better way to handle this issue). Thanks for responding!Timothy Perrigo

1 Answers

0
votes

I'm not sure if this is the best way, but I was able to get my case classes unmarshalled using something like the following; if there's better way, please let me know!

      val entity = responseEntity
      val foos: List[Foo] = Unmarshal(entity).to[List[Foo]].futureValue
      foos(0) shouldBe expectedFoo
      foos.size shouldBe 1

(Note that I had to also mixin the org.scalatest.concurrent.ScalaFutures trait)