3
votes

I am trying to simply create a json format for my case classes:

case class ImageRequest (inputs: Array[ImageObject])

case class ImageObject(data: Data)

case class Data(image: Image)

case class Image(url: String)

and here are the implicit formats:

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")
  }

I am getting the error:

> 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]                                              ^

Everything has been imported and appears to be in scope

1

1 Answers

6
votes

Change an order of implicits:

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")
}

Working example: https://scastie.scala-lang.org/Bh6ugVwVSTyOun5PG3I1lQ