Renders an object as JSON. The source can be a named page attribute read from the current controller resource, or an object supplied directly at construction. Created via ViewsBuilder.jsonView(...), jsonObjectView(...) and the boolean/message constructor from server-side JS. A JsonResult source is written with its own nice-dates formatting; any other object is converted to a JSON object or array first. Call wrapJsonResult() to wrap the rendered data in a success JsonResult envelope, for compatibility with the Kademi forms plugin.

Group: Views

Implements: View, Serializable


Properties

PropertyReturnsDescription
contentTypeStringThe content type sent with the response, JsonResult's standard JSON content type.

Methods

render(CommonResource page, OutputStream out, Range range, Map<String,String> params, String contentType)

Returns: void

Resolves the object to render (from the constructor or from the named page attribute), converts it to JSON as needed, and writes it to the response, optionally wrapped in a success JsonResult envelope.

ParameterDescription
pagethe resource the view is being rendered for; used to read the named attribute when this view was constructed with an attribute name rather than a direct object
outthe stream the JSON is written to
rangenot used by this view; the full JSON is always written
paramsrequest parameters, not used by this view
contentTypenot used by this view; getContentType() supplies the response content type

getContentType()

Returns: String

The content type sent with the response, JsonResult's standard JSON content type.

wrapJsonResult()

Returns: JsonView

Sets this view to wrap the rendered data in a success JsonResult envelope, for compatibility with the Kademi forms plugin.

To get full access to the Kademi Hub existing customers can login here, or new customers can register here.