Skip to content
Snippets Groups Projects
Commit bad96e59 authored by Will Billingsley's avatar Will Billingsley
Browse files

Added JSON library and small example

parent a0123067
No related branches found
No related tags found
No related merge requests found
package controllers;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Result;
/**
* This controller contains an action to handle HTTP requests
* to the application's home page.
*/
public class ExamplesController extends Controller {
/**
* An action that returns a JSON object, to show how Jackson and Play JSON are
* used to construct a JSON response
* @return
*/
public Result returnJson() {
ObjectNode json = Json.newObject();
json.put("Hello", "World");
ArrayNode arr = json.putArray("names");
arr.add("Alice");
arr.add("Bob");
arr.add("Charlie");
return ok(json);
}
/**
* To receive a JSON object from the body of a request, you can get it with
* request().body().asJson()
* @return
*/
public Result receiveJsonPost() {
JsonNode json = request().body().asJson();
String name = json.findPath("name").asText();
return ok("The name was " + name);
}
}
......@@ -12,3 +12,5 @@ resolvers += Resolver.url("Hopper releases", url("http://hopper.une.edu.au/artif
resolvers += Resolver.url("Hopper snapshots", url("http://hopper.une.edu.au/artifactory/libs-snapshot"))
libraryDependencies += guice
libraryDependencies += "com.typesafe.play" %% "play-json" % "2.6.10"
\ No newline at end of file
......@@ -5,5 +5,8 @@
# An example controller showing a sample home page
GET / controllers.HomeController.index
GET /example/json controllers.ExamplesController.returnJson()
POST /example/json controllers.ExamplesController.receiveJsonPost()
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
2018-09-11 01:14:07,982 [INFO] from play.api.http.EnabledFilters in play-dev-mode-akka.actor.default-dispatcher-4 - Enabled Filters (see <https://www.playframework.com/documentation/latest/Filters>):
play.filters.csrf.CSRFFilter
play.filters.headers.SecurityHeadersFilter
play.filters.hosts.AllowedHostsFilter
2018-09-11 01:14:08,089 [INFO] from play.api.Play in play-dev-mode-akka.actor.default-dispatcher-4 - Application started (Dev)
2018-09-11 01:14:08,483 [WARN] from play.api.mvc.DefaultJWTCookieDataCodec in application-akka.actor.default-dispatcher-4 - decode: cookie has invalid signature! message = JWT signature does not match locally computed signature. JWT validity cannot be asserted and should not be trusted.
2018-09-11 01:14:08,485 [INFO] from play.api.mvc.DefaultJWTCookieDataCodec in application-akka.actor.default-dispatcher-4 - The JWT signature in the cookie does not match the locally computed signature with the server.
This usually indicates the browser has a leftover cookie from another Play application,
so clearing cookies may resolve this error message.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment