【发布时间】:2017-01-20 03:05:21
【问题描述】:
我正在尝试使用 spray.io json 将案例类转换为 json。下面的代码:
case class Value(amt: Int)
case class Item(name: String, count: Value)
object MyJsonProtocol extends DefaultJsonProtocol {
implicit val itemFormat = jsonFormat2(Item)
}
import MyJsonProtocol._
import spray.json._
val json = Item("mary", Value(2)).toJson
println(json)
给予:
could not find implicit value for evidence parameter of type onextent.bluecase.examples.ex1.ExampleJson2.MyJsonProtocol.JF[Value]
我也尝试为 Value 定义一个 JsonProtocol,但结果相同。搜索stackoverflow我只看到这个与generics相关的错误,这不是。
我错过了什么? (现在重新阅读有关隐式...)
【问题讨论】: