Package play.libs

Class Jsonp

java.lang.Object
play.libs.Jsonp
All Implemented Interfaces:
play.twirl.api.Content

public class Jsonp extends Object implements play.twirl.api.Content
The JSONP Content renders a JavaScript call of a JSON object.
Example of use, provided the following route definition:
   GET  /my-service        Application.myService(callback: String)
 
The following action definition:
   public static Result myService(String callback) {
     JsonNode json = ...
     return ok(jsonp(callback, json));
   }
 
And the following request:
   GET  /my-service?callback=foo
 
The response will have content type "application/javascript" and will look like the following:
   foo({...});
 
  • Constructor Details

    • Jsonp

      public Jsonp(String padding, com.fasterxml.jackson.databind.JsonNode json)
  • Method Details

    • body

      public String body()
      Specified by:
      body in interface play.twirl.api.Content
    • contentType

      public String contentType()
      Specified by:
      contentType in interface play.twirl.api.Content
    • jsonp

      public static Jsonp jsonp(String padding, com.fasterxml.jackson.databind.JsonNode json)
      Parameters:
      padding - Name of the callback
      json - Json content
      Returns:
      A JSONP Content using padding and json.