java.lang.Object | ||||
↳ | org.springframework.context.support.ApplicationObjectSupport | |||
↳ | org.springframework.web.context.support.WebApplicationObjectSupport | |||
↳ | org.springframework.web.servlet.view.AbstractView | |||
↳ | org.springframework.web.servlet.view.json.MappingJacksonJsonView |
Spring-MVC View
that renders JSON content by serializing the model for the current request using Jackson's ObjectMapper.
By default, the entire contents of the model map (with the exception of framework-specific classes) will be
encoded as JSON. For cases where the contents of the map need to be filtered, users may specify a specific set of
model attributes to encode via the renderedAttributes
property.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | DEFAULT_CONTENT_TYPE | Default content type. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.web.servlet.view.AbstractView
|
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.context.support.ApplicationObjectSupport
| |||||||||||
From interface
org.springframework.web.servlet.View
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Construct a new
JacksonJsonView , setting the content type to application/json . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the attributes in the model that should be rendered by this view.
| |||||||||||
Disables caching of the generated JSON.
| |||||||||||
Sets the
JsonEncoding for this converter. | |||||||||||
Sets the
ObjectMapper for this view. | |||||||||||
Indicates whether the JSON output by this view should be prefixed with "
{ &&}". | |||||||||||
Sets the attributes in the model that should be rendered by this view.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Filters out undesired attributes from the given model.
| |||||||||||
Prepare the given response for rendering.
| |||||||||||
Subclasses must implement this method to actually render the view.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.web.servlet.view.AbstractView
| |||||||||||
From class
org.springframework.web.context.support.WebApplicationObjectSupport
| |||||||||||
From class
org.springframework.context.support.ApplicationObjectSupport
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.beans.factory.BeanNameAware
| |||||||||||
From interface
org.springframework.context.ApplicationContextAware
| |||||||||||
From interface
org.springframework.web.context.ServletContextAware
| |||||||||||
From interface
org.springframework.web.servlet.View
|
Default content type. Overridable as bean property.
Construct a new JacksonJsonView
, setting the content type to application/json
.
Returns the attributes in the model that should be rendered by this view.
Disables caching of the generated JSON.
Default is true
, which will prevent the client from caching the generated JSON.
Sets the JsonEncoding
for this converter. By default, JsonEncoding#UTF8 UTF-8 is used.
Sets the ObjectMapper
for this view. If not set, a default ObjectMapper#ObjectMapper() ObjectMapper
is used.
Setting a custom-configured ObjectMapper
is one way to take further control of the JSON serialization
process. For example, an extended SerializerFactory can be configured that provides custom serializers for
specific types. The other option for refining the serialization process is to use Jackson's provided annotations on
the types to be serialized, in which case a custom-configured ObjectMapper is unnecessary.
Indicates whether the JSON output by this view should be prefixed with "{
&&}". Default is false.
Prefixing the JSON string in this manner is used to help prevent JSON Hijacking. The prefix renders the string syntactically invalid as a script so that it cannot be hijacked. This prefix does not affect the evaluation of JSON, but if JSON validation is performed on the string, the prefix would need to be ignored.
Sets the attributes in the model that should be rendered by this view. When set, all other model attributes will be ignored.
Filters out undesired attributes from the given model. The return value can be either another Map
, or a
single value object.
Default implementation removes BindingResult
instances and entries not included in the renderedAttributes
property.
model | the model, as passed on to renderMergedOutputModel(Map |
---|
Prepare the given response for rendering.
The default implementation applies a workaround for an IE bug when sending download content via HTTPS.
request | current HTTP request |
---|---|
response | current HTTP response |
Subclasses must implement this method to actually render the view.
The first step will be preparing the request: In the JSP case, this would mean setting model objects as request attributes. The second step will be the actual rendering of the view, for example including the JSP via a RequestDispatcher.
model | combined output Map (never null ),
with dynamic values taking precedence over static attributes |
---|---|
request | current HTTP request |
response | current HTTP response |
Exception |
---|