spray-json和列表编组 [英] spray-json and list marshalling

查看:145
本文介绍了spray-json和列表编组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用spray-json将自定义对象的列表封送为JSON.我有以下案例类及其JsonProtocol.

I'm using spray-json to marshal lists of custom objects into JSON. I have the following case class and its 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)
}

当我尝试插入这样的路线时:

When I try to put in in a route like this one:

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]]

也许您知道出了什么问题?

Perhaps you know what is the problem?

我正在将Scala 2.10.1与Spray 1.1-M7和spray-json 1.2.5结合使用

I'm using Scala 2.10.1 with spray 1.1-M7 and spray-json 1.2.5

推荐答案

您还需要导入在路由范围内定义的格式:

You also need to import the format you defined on the route scope:

import JollyJsonProtocol._
get {
      complete {
        List(new ElementResponse(...), new ElementResponse(...))
      }
    }

这篇关于spray-json和列表编组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆