Re: [spray-user] Scala Spray Json implicit error for nested classes:

6 views
Skip to first unread message

Jan-Pieter van den Heuvel

unread,
Apr 14, 2016, 3:12:10 AM4/14/16
to spray...@googlegroups.com
Hi,

In order to marshall the TodoTxs from/to JSON you also need an implicit JsonFormat for RequestPayload in scope. It should work if you add the following line before your standardTodoFormat:

implicit val requestPayloadFormat = jsonFormat2(RequestPayload.apply)

Hope this helps.

Kind regards,
Jan-Pieter

2016-04-13 18:54 GMT+02:00 ScalaIsCool <huan...@gmail.com>:

I hit the following compile error when using Spray Json for nested classes:

Sbt Compile Error:(10, 48) could not find implicit value for evidence parameter of type:


TodoMarshalling.this.JF[io.github.scalahackers.todo.RequestPayload]  

  implicit val standardTodoFormat = jsonFormat9(TodoTxs.apply)  

                                          ^

Here is code:

trait TodoMarshalling extends SprayJsonSupport
  with FlowMaterializerProvider
  with DefaultJsonProtocol {

  implicit val standardTodoFormat = jsonFormat9(TodoTxs.apply)
  implicit val todoUpdateFormat = jsonFormat8(TodoUpdate.apply)

  def todoFormatFor(baseUrl: String) = new RootJsonFormat[TodoTxs] {
    def read(json: JsValue) = standardTodoFormat.read(json)

    def write(todo: TodoTxs) = {
      val fields = standardTodoFormat.write(todo).asJsObject.fields
      JsObject(fields.updated("url", JsString(baseUrl + '/' + todo.id)))
  }
}

}

case class TodoTxs(id: String, extid: String = "", request: RequestPayload, state: String = "",substate: String = "", response: String = "", priority: Int = 0, starttime: String = "", endtime: String = "")
case class RequestPayload(reqtype: String, reqtask: String)  

Appreciate any advice.

--
You received this message because you are subscribed to the Google Groups "spray.io User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spray-user+...@googlegroups.com.
Visit this group at https://groups.google.com/group/spray-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/spray-user/2e0a9072-32b2-4dc9-92fc-45789decfc5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages