Scala编组/解组

时间:2015-06-22 03:51:14

标签: scala spray spray-json

我试图为一个非常简单的对象编写自定义Marshaller,但似乎scala运行时无法找到它。

按照喷涂模板,我已按如下方式定义了该路线:

package com.example

import akka.actor.Actor
import spray.routing._
import spray.http._
import MediaTypes._
import com.example.dto.RecipeEntry
import com.example.dto.RecipeEntryJson._


trait RecipeManager extends HttpService {

  val myRoute =
    path("recipe") {
      post {
        decompressRequest() {
          entity(as[RecipeEntry]) { recipe =>
            complete(s"picture is $recipe.image")
          }
        }
      }
    }
}

我试图将Marshaller [RecipeEntry]定义为:

package com.example.dto

import spray.json.DefaultJsonProtocol
import spray.httpx.SprayJsonSupport._
import spray.httpx.unmarshalling._
import spray.httpx.marshalling._
import spray.http._


case class RecipeEntry(originSite: String, image: String)

object RecipeEntryJson extends DefaultJsonProtocol {

    implicit val jsonMarshaller: Marshaller[RecipeEntry] = jsonFormat2(RecipeEntry.apply)
}

但我一直收到以下错误:

  

RecipeManager.scala:18:找不到参数um的隐含值:spray.httpx.unmarshalling.FromRequestUnmarshaller [com.example.dto.RecipeEntry]   [error] entity(as [RecipeEntry]){recipe =>

事实上,我遇到与this link相同的问题,但添加import com.example.dto.RecipeEntryJson._没有帮助

我一定会遗漏一些小细节(可能还有不少,因为我对scala和喷雾很新),但我尝试过很多东西,但无济于事。非常感谢任何帮助。

0 个答案:

没有答案
相关问题