New to akka-http -
i new akka-http. using in project. not able understand marshalling , unmarshalling is.
if can explain brief example showing how marshall , unmarshall json.
when receive request in http in wire format i.e byte string, unmarshaling converting byte string higher level format, on flip side marshaling convert low level format.
example in akka-http of converting json string(str) case class(person):
case class person(name: string, age: int) val str = """{"name": "some", "aga": 10}""" impicit val jsonf = jsonformat2(person) val person = jsonparser(str).convertto[person] but better approach using entity directive akka-http:
val route = post { entity(as[person]) { person => complete(s"person: ${person.name} - favorite number: ${person.favoritenumber}") } } the example documentation here way need implicit formater in scope unmarshaling succeed , number match number of field in case class.
Comments
Post a Comment