【发布时间】:2023-03-26 21:08:01
【问题描述】:
Spray 表示任何普通数据类型,包括 Seq 都会自动(取消)编组到 JSON 或从 JSON 中获取。出于某种原因,我没有遇到这种情况。
import spray.json._
import DefaultJsonProtocol._
...
class RestAPITest
extends FlatSpec
with Matchers
with ScalatestRouteTest
with MyRoute
{
...
behavior of "MyRoute"
it should "return a list as JSON" in {
Get("/computers") ~> myRoute ~> check {
status should equal(OK)
// 'sbt test' gives:
// "could not find implicit value for evidence parameter of type spray.httpx.unmarshalling.FromResponseUnmarshaller[Seq[String]]"
//
responseAs[Seq[String]] should contain theSameElementsAs( List( "A01", "A02", "A03", "E01", "G04" ) )
}
}
我做错了什么?
【问题讨论】:
-
尝试添加
import spray.httpx.SprayJsonSupport._。 -
似乎有效,谢谢! (还有一些问题我明天会详细看到)
-
这和升级到 Spray 1.3.0 有所帮助。 'responseAs' 行在其简单性中非常棒!去 spray-json 和 scala! :) 如果您将评论作为答案,我会很乐意批准。
-
如here 所述,发布您的“附录”作为您自己问题的答案是个好主意。