Re: [akka-user] [akka-http] An issue with spay-son and collections
Konrad, Thanks for the reply! In fact I have the very same code separation: *object ApiJsonProtocol extends ApiJsonProtocoltrait ApiJsonProtocol extends SprayJsonSupport with DefaultJsonProtocol { implicit val feedFormat = jsonFormat2(Feed) // implicit val feedsWriter = seqFormat[Feed]}* *class FeedRoute(feedRepository: FeedRepository) extends ApiRoute with ApiJsonProtocol {* * override val underlying: Route = {* * pathPrefix("feeds") {* *pathEndOrSingleSlash {* *get {* *parameters('from.as[Int] ? 0, 'limit.as[Int] ? 10, 'title ? "") { (from, limit, title) =>* *complete(* *// TODO use (from, limit, title)* *feedRepository.findAll()* *)* *}* *}* *}* * }* *}* *}* But without the extra "*implicit val feedsWriter = seqFormat[Feed]*" it does not compile. On GitHub I've found several examples of people trying to solve the same problem: 1) Use of .toJson before wrapping into complete(...) https://github.com/ArchDev/akka-http-rest/blob/master/src/main/scala/me/archdev/restapi/http/routes/UsersServiceRoute.scala 2) Declaring implicit val for each Seq[of somethings] but in this particular case the author went further and coded full RootJsonWriter https://github.com/dit4c/dit4c/blob/f66f833ef35d58234391e9e0f09ad36b7a4a6206/dit4c-machineshop/src/main/scala/dit4c/machineshop/ApiService.scala So, it appears I'm not the only one who finds this a little bit confusing. Regards, Ilya -- >> Read the docs: http://akka.io/docs/ >> Check the FAQ: >> http://doc.akka.io/docs/akka/current/additional/faq.html >> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
Re: [akka-user] [akka-http] An issue with spay-son and collections
Usually one would do something like this: trait MyModelJsonProtocol extends DefaultJsonProtocol { implicit val feedFormat = jsonFormat2(Feed) } object MyModelJsonProtocol extends MyModelJsonProtocol And use it like so: trait MyHelloWorldRoute extends MyModelJsonProtocol = { val route = complete(List(Feed(...))) } Which should work AFAIR :-) -- Cheers, Konrad 'ktoso’ Malawski Akka @ Typesafe On 11 November 2015 at 14:18:57, ilya.sorokou...@gmail.com (ilya.sorokou...@gmail.com) wrote: Hi Guys, I'm trying out Akka-http on a small pet project of mine(where I'm gonna use it to implement some REST API) and I've stumbled upon an interesting problem with implicits. So, long story short it appears that I need to add an implicit Json writer for each collection-entity pair that I intend to serialize into Json. For example, in addition to: implicit val feedFormat = jsonFormat2(Feed) I need to add implicit val feedsWriter = DefaultJsonProtocol.seqFormat[Feed] so that later in the code I can simply write complete(somethingThatReturnsSeqOfFeed(...)). Otherwise, it won't compile because there is no implicit for Seq[Feed]. Did I miss something like certain import or this is indeed the expected behavior? Best Regards, Ilya -- >> Read the docs: http://akka.io/docs/ >> Check the FAQ: >> http://doc.akka.io/docs/akka/current/additional/faq.html >> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- >> Read the docs: http://akka.io/docs/ >> Check the FAQ: >> http://doc.akka.io/docs/akka/current/additional/faq.html >> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
[akka-user] [akka-http] An issue with spay-son and collections
Hi Guys, I'm trying out Akka-http on a small pet project of mine(where I'm gonna use it to implement some REST API) and I've stumbled upon an interesting problem with implicits. So, long story short it appears that I need to add an implicit Json writer for each collection-entity pair that I intend to serialize into Json. For example, in addition to: *implicit val feedFormat = jsonFormat2(Feed)* I need to add *implicit val feedsWriter = **DefaultJsonProtocol.**seqFormat[Feed]* so that later in the code I can simply write complete(somethingThatReturnsSeqOfFeed(...)). Otherwise, it won't compile because there is no implicit for Seq[Feed]. Did I miss something like certain import or this is indeed the expected behavior? Best Regards, Ilya -- >> Read the docs: http://akka.io/docs/ >> Check the FAQ: >> http://doc.akka.io/docs/akka/current/additional/faq.html >> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.