阿卡HTTP /瑟茜解码结果

问题描述 投票:2回答:1

我很抱歉,如果我失去了一些东西简单,但我试图用阿卡HTTP与瑟茜(使用akka-http-json瑟茜模块)。我试图检索它融合在ErrorAccumulatingCirceSupport性状的ScalaTest一个GET调用的结果。呼叫经历成功,但我无法解组应答......这是一个非常简单的测试,但我只是不知道如何解组的成果转化为域对象,如列表:

    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
   }

我得到的错误是:

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

如果任何人都可以指出我在做什么错了,我将非常感谢帮助!

谢谢!

json scala akka-http circe
1个回答
0
投票

我不知道这是否是最好的方式,但我能得到使用类似下面的我来说,类解组;如果有更好的办法,请让我知道!

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

(请注意,我只好也混入了org.scalatest.concurrent.ScalaFutures性状)

© www.soinside.com 2019 - 2024. All rights reserved.