required: spray.httpx.marshalling.ToResponseMarshallable Error

1,040 views
Skip to first unread message

miki haiat

unread,
Jan 25, 2015, 10:24:26 AM1/25/15
to spray...@googlegroups.com

Hey im pretty new to Spray and reactive mongo .

Im trying to return a list of result as json but i'm having some issue with converting the result to list of json.

this is my model

import reactivemongo.bson.BSONDocumentReader
import reactivemongo.bson.BSONObjectID
import reactivemongo.bson.Macros

case class Post(id: BSONObjectID, likes: Long, message: String, object_id: String, shares: Long)

object Post {
  implicit val reader: BSONDocumentReader[Post] = Macros.reader[Post]
}

and this is the route

val route1 =
    path("posts") {
      get{
        respondWithMediaType(`application/json`) {
          val res: Future[List[Post]] = mongoService.getAll()
          onComplete(res) {
            case Success(value) => complete(value)
            case Failure(ex)    => complete(ex.getMessage)
          }
        }
      }
    }


error
type mismatch; found : List[com.example.model.Post] required: spray.httpx.marshalling.ToResponseMarshallable

thanks,

miki


Stevo Slavić

unread,
Jan 25, 2015, 1:57:08 PM1/25/15
to spray...@googlegroups.com
Hello,

You need to define implicit JsonFormat for com.example.model.Post so that spray.httpx.SprayJsonSupport can provide implicit marshaller, to marshall Post instances to response.
Kind regards,
Stevo Slavic.

--
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 http://groups.google.com/group/spray-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/spray-user/7e35848f-430e-4f0d-9b9d-968b0fa19e25%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stevo Slavić

unread,
Jan 25, 2015, 2:16:23 PM1/25/15
to spray...@googlegroups.com
Btw, you'll have to provide JsonFormat for used reactivemongo types as well (e.g. BSONObjectID).
Somebody has already done it and made it OSS, see
- https://github.com/zipfworks/sprongo/blob/master/src/main/scala/com/zipfworks/sprongo/ExtendedJsonProtocol.scala
- https://github.com/zipfworks/sprongo
- http://repo1.maven.org/maven2/com/zipfworks/sprongo_2.10/1.1.1/

Kind regards,
Stevo Slavic.
Message has been deleted

miki haiat

unread,
Jan 25, 2015, 4:48:51 PM1/25/15
to spray...@googlegroups.com
Im trying sprongo but i have some issue with this code  i basically copy past it...



class DBDriver(dbUrls: Seq[String], dbName: String, system: Option[ActorSystem]) extends SprongoDB(dbUrls, dbName, system) {
 
object Post extends CollectionDAO[Post]("post")
}
not found: type SprongoDB
too many arguments
for constructor Object: ()Object
not found: type CollectionDAO



Reply all
Reply to author
Forward
0 new messages