spray / spray-json

A lightweight, clean and simple JSON implementation in Scala
Apache License 2.0
974 stars 190 forks source link

geneic class #197

Closed wsf1990 closed 7 years ago

wsf1990 commented 8 years ago

When I use spray-json like what example show:

case class MyList[A](name: String, items: List[A])

  object MyListProtocol extends DefaultJsonProtocol {
    implicit def myListFormat[A: JsonFormat] = jsonFormat2(MyList.apply[A])
  }

import MyListProtocol._
MyList[Int]("wsf", List(1, 2, 3)).toJson

It took an error and the stack is

Error:(46, 51) Cannot find JsonWriter or JsonFormat type class for MyList[Int]
    val json3 = MyList[Int]("wsf", List(1, 2, 3)).toJson
                                                  ^
wsf1990 commented 8 years ago

resolved it, I added the import DefaultJsonProtocol._ to the code which must be remove.

ancane commented 7 years ago

Hi @wsf1990. So it works for you? Could you please close the issue then?