Compiler can't find implicit values even tho I've created the JsonProtocol

101 views Asked by At

So I have this simple post endpoint where should happen some unmarshalling

post {
      path("/emails") {
        import package.model.impl.RegularEmailJsonSupport._
        entity(as[RegularEmail]) { regularEmail =>
          storeInboundEmails(regularEmail).runDB.attempt.unsafeRunSync()
     }
}

This is the model class alongside the json protocol format in which I don't have much confidence that is correct for the EmailStatus field

case class RegularEmail(
    id: BigInt,
    timestamp: DateTime,
    senderEmailAddress: String,
    originalRecipientsAddresses: List[String],
    cc: List[String],
    subject: String,
    content: JsValue,
    customerNumber: Int,
    status: EmailStatus = EmailStatus.UNREAD,
    originalSenderEmailAddress: String,
    hasAttachments: Boolean = false
//metadata: Option[EmailMetadata]
) extends Email(
  id = id,
  timestamp = timestamp,
  senderEmailAddress = senderEmailAddress,
  originalRecipientsAddresses = originalRecipientsAddresses,
  cc = cc,
  subject = subject,
  content = content,
  status = status,
  hasAttachments = hasAttachments,
  sourceType = EmailSourceType.REGULAR //,
//metadata = metadata
) {
}

object RegularEmailJsonSupport extends DefaultJsonProtocol with SprayJsonSupport {
  implicit val eventDataFormat = jsonFormat1(DateTime.apply)
  implicit val statusFormat = jsonFormat1(EmailStatus.apply)
  implicit val EmailFormat = jsonFormat11(RegularEmail.apply)
}

And these are the errors I get

could not find implicit value for parameter um: akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller


could not find implicit value for evidence parameter of type RegularEmailJsonSupport.JF[P1] (Cannot find JsonWriter or JsonFormat type class for P1)
[error]   implicit val statusFormat = jsonFormat1(EmailStatus.apply)

I also see that the compiler doesn't complain about the jsonFormat for DateTime, so could this problem be provoked by EmailStatus?

EmailStatus is an object in the abstract class Email that gets inherited by RegularEmail and looks like this:

object EmailStatus extends Enumeration {
  type EmailStatus = Value
  val READ, UNREAD, CLOSED = Value
}
0

There are 0 answers