open class MappingJackson2JsonView : AbstractJackson2View
Spring MVC View that renders JSON content by serializing the model for the current request using Jackson 2's ObjectMapper.
By default, the entire contents of the model map (with the exception of framework-specific classes) will be encoded as JSON. If the model contains only one key, you can have it extracted encoded as JSON alone via #setExtractValueFromSingleKeyModel
.
The default constructor uses the default configuration provided by Jackson2ObjectMapperBuilder.
Compatible with Jackson 2.6 and higher, as of Spring 4.3.
Author
Jeremy Grelle
Author
Arjen Poutsma
Author
Rossen Stoyanchev
Author
Juergen Hoeller
Author
Sebastien Deleuze
Since
3.1.2
MappingJackson2JsonView()
Construct a new MappingJackson2JsonView(objectMapper: ObjectMapper)
Construct a new |
static val DEFAULT_CONTENT_TYPE: String
Default content type: "application/json". Overridable through |
|
static val DEFAULT_JSONP_CONTENT_TYPE: String
Default content type for JSONP: "application/javascript". |
fun getModelKeys(): MutableSet<String>
Return the attributes in the model that should be rendered by this view. |
|
open fun setExtractValueFromSingleKeyModel(extractValueFromSingleKeyModel: Boolean): Unit
Set whether to serialize models containing a single attribute as a map or whether to extract the single value from the model and serialize it directly. The effect of setting this flag is similar to using Default is |
|
open fun setJsonPrefix(jsonPrefix: String): Unit
Specify a custom prefix to use for this view's JSON output. Default is none. |
|
open fun setJsonpParameterNames(jsonpParameterNames: MutableSet<String>): Unit
Set JSONP request parameter names. Each time a request has one of those parameters, the resulting JSON will be wrapped into a function named as specified by the JSONP request parameter value. The parameter names configured by default are "jsonp" and "callback". |
|
open fun setModelKey(modelKey: String): Unit
{@inheritDoc} |
|
open fun setModelKeys(modelKeys: MutableSet<String>): Unit
Set the attributes in the model that should be rendered by this view. When set, all other model attributes will be ignored. |
|
open fun setPrefixJson(prefixJson: Boolean): Unit
Indicates whether the JSON output by this view should be prefixed with ")]}', ". Default is 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 should be stripped before parsing the string as JSON. |