类 MappingJackson2JsonView
- 所有已实现的接口:
cn.taketoday.beans.factory.Aware,cn.taketoday.beans.factory.BeanNameAware,cn.taketoday.context.ApplicationContextAware,View
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(boolean).
The default constructor uses the default configuration provided by Jackson2ObjectMapperBuilder.
Compatible with Jackson 2.9 to 2.12
- 从以下版本开始:
- 4.0
- 作者:
- Jeremy Grelle, Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller, Sebastien Deleuze, Harry Yang
-
字段概要
字段修饰符和类型字段说明static final StringDefault content type: "application/json".private booleanprivate String从类继承的字段 cn.taketoday.web.view.json.AbstractJackson2View
updateContentLength从类继承的字段 cn.taketoday.context.support.ApplicationObjectSupport
applicationContext, log, messageSourceAccessor从接口继承的字段 cn.taketoday.web.view.View
RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE -
构造器概要
构造器构造器说明Construct a newMappingJackson2JsonViewusing default configuration provided byJackson2ObjectMapperBuilderand setting the content type toapplication/json.MappingJackson2JsonView(ObjectMapper objectMapper) Construct a newMappingJackson2JsonViewusing the providedObjectMapperand setting the content type toapplication/json. -
方法概要
修饰符和类型方法说明protected ObjectfilterModel(Map<String, Object> model) Filter out undesired attributes from the given model.Return the attributes in the model that should be rendered by this view.voidsetExtractValueFromSingleKeyModel(boolean extractValueFromSingleKeyModel) 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.voidsetJsonPrefix(String jsonPrefix) Specify a custom prefix to use for this view's JSON output.voidsetModelKey(String modelKey) Set the attribute in the model that should be rendered by this view.voidsetModelKeys(Set<String> modelKeys) Set the attributes in the model that should be rendered by this view.voidsetPrefixJson(boolean prefixJson) Indicates whether the JSON output by this view should be prefixed with ")]}', ".protected voidwritePrefix(JsonGenerator generator, Object object) Write a prefix before the main content.从类继承的方法 cn.taketoday.web.view.json.AbstractJackson2View
filterAndWrapModel, getEncoding, getObjectMapper, prepareResponse, renderMergedOutputModel, setDisableCaching, setEncoding, setObjectMapper, setPrettyPrint, setUpdateContentLength, writeContent, writeSuffix从类继承的方法 cn.taketoday.web.view.AbstractView
addStaticAttribute, createMergedOutputModel, createTemporaryOutputStream, exposeModelAsRequestAttributes, formatViewName, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getRequestContextToExpose, getStaticAttributes, isExposePathVariables, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposeOutputRedirectModel, setExposePathVariables, setRequestContextAttribute, setResponseContentType, toString, writeToResponse从类继承的方法 cn.taketoday.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, initApplicationContext, isContextRequired, obtainApplicationContext, requiredContextClass, setApplicationContext, unwrapContext, unwrapFactory
-
字段详细资料
-
DEFAULT_CONTENT_TYPE
Default content type: "application/json". Overridable throughAbstractView.setContentType(java.lang.String).- 另请参阅:
-
jsonPrefix
-
modelKeys
-
extractValueFromSingleKeyModel
private boolean extractValueFromSingleKeyModel
-
-
构造器详细资料
-
MappingJackson2JsonView
public MappingJackson2JsonView()Construct a newMappingJackson2JsonViewusing default configuration provided byJackson2ObjectMapperBuilderand setting the content type toapplication/json. -
MappingJackson2JsonView
Construct a newMappingJackson2JsonViewusing the providedObjectMapperand setting the content type toapplication/json.
-
-
方法详细资料
-
setJsonPrefix
Specify a custom prefix to use for this view's JSON output. Default is none.- 另请参阅:
-
setPrefixJson
public void setPrefixJson(boolean prefixJson) Indicates whether the JSON output by this view should be prefixed with ")]}', ". Default isfalse.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.
-
setModelKey
Set the attribute in the model that should be rendered by this view. When set, all other model attributes will be ignored.- 指定者:
setModelKey在类中AbstractJackson2View
-
setModelKeys
Set the attributes in the model that should be rendered by this view. When set, all other model attributes will be ignored. -
getModelKeys
Return the attributes in the model that should be rendered by this view. -
setExtractValueFromSingleKeyModel
public void setExtractValueFromSingleKeyModel(boolean extractValueFromSingleKeyModel) 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
MappingJackson2HttpMessageConverterwith an@ResponseBodyrequest-handling method.Default is
false. -
filterModel
Filter out undesired attributes from the given model. The return value can be either anotherMapor a single value object.- 指定者:
filterModel在类中AbstractJackson2View- 参数:
model- the model, as passed on toAbstractJackson2View.renderMergedOutputModel(java.util.Map<java.lang.String, java.lang.Object>, cn.taketoday.web.RequestContext)- 返回:
- the value to be rendered
-
writePrefix
从类复制的说明:AbstractJackson2ViewWrite a prefix before the main content.- 覆盖:
writePrefix在类中AbstractJackson2View- 参数:
generator- the generator to use for writing content.object- the object to write to the output message.- 抛出:
IOException
-