我正在尝试为我的案例类创建一个json格式:
case class ImageRequest (inputs: Array[ImageObject])
case class ImageObject(data: Data)
case class Data(image: Image)
case class Image(url: String)
以下是隐式格式:
object ApplicationProtocol extends DefaultJsonProtocol {
lazy implicit val ImageRequestFormat = jsonFormat(ImageRequest, "inputs")
lazy implicit val ImageObjectFormat = jsonFormat(ImageObject, "data")
lazy implicit val DataFormat = jsonFormat(Data, "image")
lazy implicit val ImageFormat = jsonFormat(Image, "url")
}
我收到错误:
> could not find implicit value for evidence parameter of type
> connectors.ClarifaiConnector.ApplicationProtocol.JF[Array[model.ImageObject]]
> [error] lazy implicit val ImageRequestFormat =
> jsonFormat(ImageRequest, "inputs") [error]
> ^ [error]
> /Users/MacZ/Dropbox/Work/Development/JobOffer/ImageProject/src/main/scala/connectors/clarifaiConnector.scala:27:53:
> could not find implicit value for evidence parameter of type
> connectors.ClarifaiConnector.ApplicationProtocol.JF[model.Data]
> [error] lazy implicit val ImageObjectFormat =
> jsonFormat(ImageObject, "data") [error]
> ^ [error]
> /Users/MacZ/Dropbox/Work/Development/JobOffer/ImageProject/src/main/scala/connectors/clarifaiConnector.scala:28:46:
> could not find implicit value for evidence parameter of type
> connectors.ClarifaiConnector.ApplicationProtocol.JF[model.Image]
> [error] lazy implicit val DataFormat = jsonFormat(Data, "image")
> [error] ^
所有内容都已导入并且似乎在范围内
答案 0 :(得分:5)
更改隐含的顺序:
object ApplicationProtocol extends DefaultJsonProtocol {
implicit val ImageFormat = jsonFormat(Image, "url")
implicit val DataFormat = jsonFormat(Data, "image")
implicit val ImageObjectFormat = jsonFormat(ImageObject, "data")
implicit val ImageRequestFormat = jsonFormat(ImageRequest, "inputs")
}