如何在喷雾中使用Marshall(A).to [B]将案例类转换为RequestEntity

时间:2019-05-13 14:22:21

标签: scala akka marshalling spray-json

我有case类,我需要使用spray-json库将其转换为RequestEntity类型。我遇到错误说,“找不到隐式参数m的参数:Marshaller [NotificationPushEvent.Type,RequestEntity]。

案例类代码

case class NotificationPushEvent(
    id: String,
    channelId: String,
    recipients: Seq[String],
    externalId: NCFItemExternalId,
    eventType: EventType.Value,
    notAfter: Option[DateTime],
    timestamp: DateTime,
    sender: Sender,
    correlatedItems: Option[Seq[CorrelatedItem]],
    title: Option[String],
    descriptionMimeType: Option[String],
    description: Option[String],
    links: Option[Seq[NCFExternalLink]],
    reason: Option[String]
) 

转换功能

  def postData(pushEvent: NotificationPushEvent)(implicit executionContext: ExecutionContext): Future[HttpResponse] ={
    //implicit val m: Marshaller[NotificationPushEvent => RequestEntity] =
    checkUserExistence(pushEvent).map { response =>
      response.map {
        case HttpResponse(StatusCodes.OK, _, _, _) =>
          Marshal(NotificationPushEvent).to[RequestEntity]flatMap { entity =>
            //TODO form URl
            val request = HttpRequest(method = HttpMethods.POST, uri = s"/channels/${pushEvent.channelId}", entity = entity)
            getInstance().singleRequest(request)
          }
      }
    }
  }

0 个答案:

没有答案