play.libs
Class Jsonp

java.lang.Object
  extended by play.libs.Jsonp
All Implemented Interfaces:
play.api.mvc.Content

public class Jsonp
extends java.lang.Object
implements 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 “text/javascript” and will look like the following:
   foo({...});
 


Constructor Summary
Jsonp(java.lang.String padding, com.fasterxml.jackson.databind.JsonNode json)
           
 
Method Summary
 java.lang.String body()
           
 java.lang.String contentType()
           
static Jsonp jsonp(java.lang.String padding, com.fasterxml.jackson.databind.JsonNode json)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Jsonp

public Jsonp(java.lang.String padding,
             com.fasterxml.jackson.databind.JsonNode json)
Method Detail

body

public java.lang.String body()
Specified by:
body in interface play.api.mvc.Content

contentType

public java.lang.String contentType()
Specified by:
contentType in interface play.api.mvc.Content

jsonp

public static Jsonp jsonp(java.lang.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.