scala – spray-json和列表编组
发布时间:2020-12-16 19:07:08 所属栏目:安全 来源:网络整理
导读:我使用spray-json来将自定义对象的列表组织成 JSON.我有以下case类和它的JsonProtocol. case class ElementResponse(name: String,symbol: String,code: String,pkwiu: String,remarks: String,priceNetto: BigDecimal,priceBrutto: BigDecimal,vat: Int,min
我使用spray-json来将自定义对象的列表组织成
JSON.我有以下case类和它的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喷雾1.1-M7和spray-json 1.2.5 解决方法
您还需要导入您在路由范围上定义的格式:
import JollyJsonProtocol._ get { complete { List(new ElementResponse(...),new ElementResponse(...)) } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |