简体   繁体   中英

Scala compile error - could not find implicit value for evidence parameter of type

I am using spray json serialization for my following case class

case class ActivationMessage(override val transid: TransactionId,
                             action: FullyQualifiedEntityName,
                             revision: DocRevision,
                             user: Identity,
                             activationId: ActivationId,
                             activationNamespace: EntityPath,
                             content: Option[JsObject],
                             cause: Option[ActivationId] = None,
                             traceMetadata: Option[SpanMetadata] = None
                            ) extends Message {

  def meta = JsObject("meta" -> {
    cause map {
      c => JsObject(c.toJsObject.fields ++  activationId.toJsObject.fields)
    } getOrElse {
      activationId.toJsObject
    }
  })

  override def serialize = ActivationMessage.serdes.write(this).compactPrint

  override def toString = {
    val value = (content getOrElse JsObject()).compactPrint
    s"$action?message=$value"
  }

  def causedBySequence: Boolean = cause.isDefined
}

object ActivationMessage extends DefaultJsonProtocol {
  def parse(msg: String) = Try(serdes.read(msg.parseJson))
  private implicit val fqnSerdes = FullyQualifiedEntityName.serdes
  implicit val serdes = jsonFormat9(ActivationMessage.apply)
}

I get compilation error saying - could not find implicit value for evidence parameter of type ActivationMessage.JF[Option[com.github.levkhomich.akka.tracing.SpanMetadata]]

If I remove last argument from constructor and use jsonFormat8 every thing compiles fine. How can I add this extra argument without any compile issues?

The compiler cannot find implicit JsonFormat for SpanMetadata . Try:

...
object ActivationMessage extends DefaultJsonProtocol {
  ...
  private implicit val spanMetaSerdes = jsonFormat4(SpanMetadata.apply)
  implicit val serdes = jsonFormat9(ActivationMessage.apply)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM