Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 932
Marcin Cylke Avatar asked Jul 18 '13 21:07

Marcin Cylke


People also ask

What is spray JSON?

spray-json is a lightweight, clean and efficient JSON implementation in Scala. It supports the following features: A simple immutable model of the JSON language elements. An efficient JSON parser. Choice of either compact or pretty JSON-to-string printing.

What is spray in Scala?

spray is an open-source toolkit for building REST/HTTP-based integration layers on top of Scala and Akka. Being asynchronous, actor-based, fast, lightweight, modular and testable it's a great way to connect your Scala applications to the world.


1 Answers

This is an old issue, but I feel like giving my 2c. Was looking at similar issues today.

Marcin, it seems your issue was not actually solved (as far as I can read) - why did you accept one answer?

Did you try adding import spray.json.DefaultJsonProtocol._ in places? Those are in charge of making things such as Seqs, Maps, Options and Tuples to work. I would assume this might be the cause of your problem, since it's the List that is not getting converted.

like image 93
akauppi Avatar answered Oct 19 '22 13:10

akauppi