O'Reilly logo

RESTful Web Services with Scala by Jos Dirksen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Advanced validation and JSON support

For the final example, we're going to add JSON support to the service and some more advanced validations. To test the examples in this section, run sbt runCH04-runCH04Step3.

Add JSON support

Let's start by adding JSON support. First off, add the following dependencies to the SBT build file:

"org.json4s"   %% "json4s-jackson" % "3.2.9",
"org.scalatra" %% "scalatra-json" % scalatraVersion,

Adding JSON support only takes a couple of simple steps. First, change the class definition of our route to the following:

class ScalatraStep3(system: ActorSystem) extends ScalatraServlet
                  with FutureSupport
                  with JacksonJsonSupport {

With the JacksonJsonSupport trait added, we next need to add the following line to enable automatic ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required