This seems to be enjoyed by people and has a ticket here: https://github.com/scalapb/ScalaPB/issues/247
Hope @alanbur from that thread will be able to contribute the docs:)
This is NOT about shipping library support, only about "this is how to do it"
On 07/03/18 16:11, ktoso wrote:
This is NOT about shipping library support, only about "this is how to do it"
Exactly so - the discussion in the original bug makes that point and I
agree that all that's really needed is some example code in the docs.
--
I ran into issues smoothly integrating akka-http with scalapb and spent some time getting the datatypes to line up, I came up with this:
import akka.http.scaladsl.unmarshalling.{FromEntityUnmarshaller, Unmarshaller}
import scalapb.json4s.JsonFormat
import scalapb.{GeneratedMessage, GeneratedMessageCompanion}
trait ClientMarshallingProtocol {
implicit def unmarshalProto[T <: GeneratedMessage with scalapb.Message[T] : GeneratedMessageCompanion : Manifest]: FromEntityUnmarshaller[T] = {
Unmarshaller.stringUnmarshaller.map(JsonFormat.fromJsonString[T](_))
}
}
This needs a reference to scalapb-json4s in build.sbt (grab the newest version):
"com.thesamet.scalapb" %% "scalapb-json4s" % "0.7.0"
Then just have your Routes mixin ClientMarshallingProtocol and this sample usage should build and run without problem:
pathPrefix(myPrefix) {
post {
entity(as[MyIncomingRequest]) { myIncomingRequest =>
...
I don't know how/where to put this info in the docs to close the ticket, so I'll just leave it here and hopefully it helps out others :)
Thanks for sharing, @micmorris.
Most helpful comment
I ran into issues smoothly integrating
akka-httpwithscalapband spent some time getting the datatypes to line up, I came up with this:This needs a reference to
scalapb-json4sinbuild.sbt(grab the newest version):Then just have your
RoutesmixinClientMarshallingProtocoland this sample usage should build and run without problem:I don't know how/where to put this info in the docs to close the ticket, so I'll just leave it here and hopefully it helps out others :)