Last active
December 16, 2016 15:07
-
-
Save gabfssilva/1c25cefafe3cb4a543cdbc2ecdd0ab4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.fasterxml.jackson.databind.ObjectMapper | |
import com.fasterxml.jackson.module.scala.DefaultScalaModule | |
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper | |
import spark.ResponseTransformer | |
import spark.Spark._ | |
object MainClass { | |
val objectMapper = new ObjectMapper with ScalaObjectMapper | |
objectMapper.registerModule(DefaultScalaModule) | |
val transformer: ResponseTransformer = (model) => objectMapper.writeValueAsString(model) | |
case class Person(id: Long, name: String, age: Int) | |
def main(args: Array[String]): Unit = { | |
port(8080) | |
get("/hello", (_, _) => Person(1L, "Gabriel", 23), transformer) | |
after("/*", (_, resp) => { | |
resp.`type`("application/json") | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment