How it works...
In this recipe, you learned how to easily marshal and unmarshal your case classes to and from JSON, using spray-json and akka-http-spray-json. As we can see in the definition of our route, just by calling entity(as[Order]), the route knows how to format the incoming JSON object into an Order object. The same happens when you return either an Order or GrandTotal object in the complete block.
The route looks for an implicitly defined marshaler to achieve this purpose. This functionality is brought through our OrderJsonSupport trait, thanks to SprayJsonSupport. SprayJsonSupport checks whether there is any implicitly defined JSON formatter for your type and uses it to do the serializing. In our case, we had three implicitly defined ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access