Akka HTTP uses the spray-json library for JSON support. But this year I’ve been spending some time learning the json4s
library so I wanted to leverage that time investment in the context of Akka HTTP.
Here’s a quick walkthru of how to use the json4s
with Akka HTTP.
Dependencies
I am using Gradle, so here is the relevant code from build.gradle
To get akka http and json4s to play nicely together, I am going to leverage a open source library I found on Github: akka-http-json
The implementation will involve creating a custom Trait
that extends that akka-http-json
library and also scopes the necessary implicit
values.
Here’s our sample web server file that handles a GET
request and responds with JSON:
In main
class:
In the next post we will setup a POST
endpoint and “unmarshall” some Json.