binshi
binshi

Reputation: 1328

Cannot find JsonWriter or JsonFormat type class

The below code is unable to find JsonWriter or JsonFormat type class:

import com.typesafe.scalalogging.LazyLogging
import spray.json._

case class MatcherRequest2(dataType:String, testType:String)

object MatcherWriterJsonSupport2 extends /*SprayJsonSupport with*/ DefaultJsonProtocol {
  implicit val matcherRequest = jsonFormat2(MatcherRequest2)
}

object MatcherTransfer2 extends LazyLogging {
  import MatcherWriterJsonSupport2.rmobMatcherRequest
  def fetchSignExtractionDone: Unit = {

    val matcherRequest: MatcherRequest2 = MatcherRequest2("FeatureCollection", "testC")
    matcherRequest.toJson
  }
}

Error:

Error:(24, 24) Cannot find JsonWriter or JsonFormat type class for MatcherRequest2 rmobMatcherRequest.toJson

Error:(24, 24) not enough arguments for method toJson: (implicit writer: spray.json.JsonWriter[MatcherRequest2])spray.json.JsValue. Unspecified value parameter writer. rmobMatcherRequest.toJson

Upvotes: 0

Views: 1301

Answers (1)

binshi
binshi

Reputation: 1328

Ugh, my bad. The variable name matcherRequest is same for implicit variable and in the MatcherTransfer2 object which was causing the above error.

implicit val matcherRequest = jsonFormat2(MatcherRequest2)

replace by

implicit val matcherRequestFormat = jsonFormat2(MatcherRequest2)

Upvotes: 3

Related Questions