Spray json marshalling -


i'm on quest create json api of models nicely generalized. i'm newbie in spray, started out spike on simplified example.

however can't figure out going on bellow code...

i have imported both

  • my custom implicits and
  • spray.httpx.sprayjsonsupport._

as understand have in order have implicit in scope can convert jsonformat marshaller.

compiler error:

testservice.scala:15: not find implicit value parameter um: spray.httpx.unmarshalling.fromrequestunmarshaller[my.company.test[my.company.x]]

code:

package my.company  import spray.routing.httpservice import spray.json.{jsvalue, jsobject, jsonformat, defaultjsonprotocol}   trait testservice extends httpservice {    import my.company.testimplicits._   import spray.httpx.sprayjsonsupport._    val test =     path("test") {       post {         entity(as[test[x]]) {           test => {             complete(s"type: ${test.common}")           }         }       }     } }  trait common {   def commondata: string }  case class x(id: long, commondata: string) extends common case class y(commondata: string) extends common  case class test[t <: common](comment: string, common: t)  object testimplicits extends defaultjsonprotocol {    implicit val xformat = jsonformat2(x)   implicit val yformat = jsonformat1(y)    implicit val ytestformat: jsonformat[test[y]] = new jsonformat[test[y]] {     def write(test: test[y]) = jsobject()     def read(js: jsvalue) = test("test", y("y"))   }    implicit val xtestformat: jsonformat[test[x]] = new jsonformat[test[x]] {     def write(test: test[x]) = jsobject()     def read(js: jsvalue) = test("test", x(1l, "y"))   } } 

i appreciate help. in advance.

solved

solution (as @jrudolp suggested) both to:

  • move implicit definitions on top of file (surprising)
  • create rootjsonformat rather jsonformat.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -