我使用spray-json
将某些案例类转换为 json,但我在将 List 转换为 json 时遇到了麻烦:
case class Foo(id: Int)
object FooJsonSupport extends DefaultJsonProtocol with SprayJsonSupport {
implicit val fooFormats = jsonFormat1(Foo)
}
//and i have a list with Foo:
val list = List(Foo(1), Foo(2), Foo(3))
// and i want to return json response
post {
respondWithMediaType(`application/json`) {
complete(list)
}
}
运行示例后,出现错误:
找不到参数编组器的隐式值:spray.httpx.marshalling.ToResponseMarshaller[scala.collection.immutable.List[Post]]
如何解决?