Package play.libs

Class Jsonp

  • All Implemented Interfaces:

    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:
    • Constructor Detail

      • Jsonp

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

      • 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)
        padding - Name of the callback
        json - Json content
        A JSONP Content using padding and json.