Marcin Cylke Marcin Cylke - 1 month ago 20
Scala Question

spray-json and list marshalling

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(...))
}
}


I get an error saying that:

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?

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

Answer

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

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