Skip to content

Instantly share code, notes, and snippets.

@searler
Created June 16, 2016 23:01
Show Gist options
  • Save searler/db90de8fbcc0890c584a79ecf775c976 to your computer and use it in GitHub Desktop.
Save searler/db90de8fbcc0890c584a79ecf775c976 to your computer and use it in GitHub Desktop.
Marshalling a simple case class to/from string representation for Akka HTTP
case class A(code:Int)
import akka.http.scaladsl.marshalling.PredefinedToEntityMarshallers._
import akka.http.scaladsl.unmarshalling.PredefinedFromEntityUnmarshallers._
implicit val aResponseUnmarshaller = stringUnmarshaller.map {s:String => A(s.toInt) }
implicit val aResponseMarshaller = StringMarshaller.compose{p:A => p.code.toString}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment