如果我错过了一些简单的东西,我很抱歉,但我正在尝试通过Circe使用Akka HTTP (使用akka-http-json Circe模块)。我试图在混合了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
如果有人能指出我做错了什么,我将不胜感激!
谢谢!
发布于 2019-02-08 00:08:37
我不确定这是否是最好的方法,但是我可以使用下面的代码解组我的case类;如果有更好的方法,请让我知道!
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
特性)
https://stackoverflow.com/questions/54575935
复制相似问题