Explorar el Código

Merge pull request #1946 from AmirKarimi/patch-1

Move Json writer out side of the action method
ssmith-techempower hace 9 años
padre
commit
d93e49fdf2

+ 3 - 2
frameworks/Scala/play2-scala/play2-scala/app/controllers/Application.scala

@@ -14,10 +14,11 @@ class Application extends Controller {
 
   // Easy ones
   case class HelloWorld(message: String)
+  implicit val helloWorldWrites = Json.writes[HelloWorld]
 
   def getJsonMessage = Action {
     val helloWorld = HelloWorld(message = "Hello, World!")
-    Ok(Json.toJson(helloWorld)(Json.writes[HelloWorld])).withHeaders(CONTENT_TYPE -> "application/json")
+    Ok(Json.toJson(helloWorld)).withHeaders(CONTENT_TYPE -> "application/json")
   }
 
   val plaintext = Action {
@@ -25,4 +26,4 @@ class Application extends Controller {
     // BUT the test harness has a WARN state and says we don't need it.
     Ok("Hello, World!").withHeaders(CONTENT_TYPE -> "text/plain")
   }
-}
+}