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
| Property | Returns | Description |
|---|---|---|
| contentType | String | The 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.
| Parameter | Description |
|---|---|
page | the 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 |
out | the stream the JSON is written to |
range | not used by this view; the full JSON is always written |
params | request parameters, not used by this view |
contentType | not 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.