Scala Marshalling/Unmarshalling

783 views Asked by At

I'm trying to write a custom Marshaller for a very simple object, but it seems the scala runtime is not able to find it.

Following the spray template, I've defined the route as follows:

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")
          }
        }
      }
    }
}

and I've tried to define the Marshaller[RecipeEntry] as such:

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)
}

but I keep getting the following error:

RecipeManager.scala:18: could not find implicit value for parameter um: spray.httpx.unmarshalling.FromRequestUnmarshaller[com.example.dto.RecipeEntry] [error] entity(as[RecipeEntry]) { recipe =>

In fact, I'm running into the same problem as this link, however adding import com.example.dto.RecipeEntryJson._ did not help

I must be missing some small detail (probably quite a few, as I'm very new to scala and spray), but I've tried a number of things but to no avail. Any help is very much appreciated.

0

There are 0 answers