19.12 JSON Mapping View
TheMappingJackson2JsonView
uses the Jackson library’sObjectMapper
to render the response content as JSON. 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 theRenderedAttributes
property. TheextractValueFromSingleKeyModel
property may also be used to have the value in single-key models extracted and serialized directly rather than as a map of model attributes.
JSON mapping can be customized as needed through the use of Jackson’s provided annotations. When further control is needed, a customObjectMapper
can be injected through theObjectMapper
property for cases where custom JSON serializers/deserializers need to be provided for specific types.
JSONPis supported and automatically enabled when the request has a query parameter namedjsonp
orcallback
. The JSONP query parameter name(s) could be customized through thejsonpParameterNames
property.