我使用spray-json
将一些case类转换为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)
}
}
运行示例后,我收到错误:
无法找到参数marshaller的隐含值:spray.httpx.marshalling.ToResponseMarshaller [scala.collection.immutable.List [Post]]
如何解决?