我正在使用spray-json将自定义对象列表整理为JSON。我有以下案例类及其JsonProtocol。
case class ElementResponse(name: String, symbol: String, code: String, pkwiu: String, remarks: String, priceNetto: BigDecimal, priceBrutto: BigDecimal, vat: Int, minInStock:Int, maxInStock: Int)
object JollyJsonProtocol extends DefaultJsonProtocol with SprayJsonSupport {
implicit val elementFormat = jsonFormat10(ElementResponse)
}
当我尝试放入这样的路线时:
get {
complete {
List(new ElementResponse(...), new ElementResponse(...))
}
}
我收到一条错误消息:
could not find implicit value for evidence parameter of type spray.httpx.marshalling.Marshaller[List[pl.ftang.scala.polka.rest.ElementResponse]]
也许您知道出了什么问题?
我正在将Scala 2.10.1与Spray 1.1-M7和spray-json 1.2.5一起使用
最佳答案
您还需要导入在路由范围内定义的格式:
import JollyJsonProtocol._
get {
complete {
List(new ElementResponse(...), new ElementResponse(...))
}
}