类 AbstractJackson2View
- 所有已实现的接口:
cn.taketoday.beans.factory.Aware,cn.taketoday.beans.factory.BeanNameAware,cn.taketoday.context.ApplicationContextAware,View
AbstractView implementations.
Compatible with Jackson 2.9 to 2.12
- 从以下版本开始:
- 4.0
- 作者:
- Jeremy Grelle, Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller, Sebastien Deleuze, Harry Yang
-
字段概要
字段修饰符和类型字段说明private booleanprivate JsonEncodingprivate ObjectMapperprivate Booleanprotected boolean从类继承的字段 cn.taketoday.web.view.AbstractView
DEFAULT_CONTENT_TYPE从类继承的字段 cn.taketoday.context.support.ApplicationObjectSupport
applicationContext, log, messageSourceAccessor从接口继承的字段 cn.taketoday.web.view.View
RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明private voidprotected ObjectfilterAndWrapModel(Map<String, Object> model, RequestContext request) Filter and optionally wrap the model inMappingJacksonValuecontainer.protected abstract ObjectfilterModel(Map<String, Object> model) Filter out undesired attributes from the given model.final JsonEncodingReturn theJsonEncodingfor this view.final ObjectMapperReturn theObjectMapperfor this view.protected voidprepareResponse(RequestContext context) Prepare the given response for rendering.protected voidrenderMergedOutputModel(Map<String, Object> model, RequestContext request) Subclasses must implement this method to actually render the view.voidsetDisableCaching(boolean disableCaching) Disables caching of the generated JSON.voidsetEncoding(JsonEncoding encoding) Set theJsonEncodingfor this view.abstract voidsetModelKey(String modelKey) Set the attribute in the model that should be rendered by this view.voidsetObjectMapper(ObjectMapper objectMapper) Set theObjectMapperfor this view.voidsetPrettyPrint(boolean prettyPrint) Whether to use the default pretty printer when writing the output.voidsetUpdateContentLength(boolean updateContentLength) Whether to update the 'Content-Length' header of the response.protected voidwriteContent(OutputStream stream, Object object) Write the actual JSON content to the stream.protected voidwritePrefix(JsonGenerator generator, Object object) Write a prefix before the main content.protected voidwriteSuffix(JsonGenerator generator, Object object) Write a suffix after the main content.从类继承的方法 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
-
字段详细资料
-
objectMapper
-
encoding
-
prettyPrint
-
disableCaching
private boolean disableCaching -
updateContentLength
protected boolean updateContentLength
-
-
构造器详细资料
-
AbstractJackson2View
-
-
方法详细资料
-
setObjectMapper
Set theObjectMapperfor this view. If not set, a defaultObjectMapperwill be used.Setting a custom-configured
ObjectMapperis one way to take further control of the JSON serialization process. The other option is to use Jackson's provided annotations on the types to be serialized, in which case a custom-configured ObjectMapper is unnecessary. -
getObjectMapper
Return theObjectMapperfor this view. -
setEncoding
Set theJsonEncodingfor this view. By default, UTF-8 is used. -
getEncoding
Return theJsonEncodingfor this view. -
setPrettyPrint
public void setPrettyPrint(boolean prettyPrint) Whether to use the default pretty printer when writing the output. This is a shortcut for setting up anObjectMapperas follows:ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
The default value is
false. -
configurePrettyPrint
private void configurePrettyPrint() -
setDisableCaching
public void setDisableCaching(boolean disableCaching) Disables caching of the generated JSON.Default is
true, which will prevent the client from caching the generated JSON. -
setUpdateContentLength
public void setUpdateContentLength(boolean updateContentLength) Whether to update the 'Content-Length' header of the response. When set totrue, the response is buffered in order to determine the content length and set the 'Content-Length' header of the response.The default setting is
false. -
prepareResponse
从类复制的说明:AbstractViewPrepare the given response for rendering.The default implementation applies a workaround for an IE bug when sending download content via HTTPS.
- 覆盖:
prepareResponse在类中AbstractView- 参数:
context- current HTTP request context
-
renderMergedOutputModel
protected void renderMergedOutputModel(Map<String, Object> model, RequestContext request) throws Exception从类复制的说明:AbstractViewSubclasses 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.
- 指定者:
renderMergedOutputModel在类中AbstractView- 参数:
model- combined output Map (nevernull), with dynamic values taking precedence over static attributesrequest- current HTTP request context- 抛出:
Exception- if rendering failed
-
filterAndWrapModel
Filter and optionally wrap the model inMappingJacksonValuecontainer.- 参数:
model- the model, as passed on torenderMergedOutputModel(java.util.Map<java.lang.String, java.lang.Object>, cn.taketoday.web.RequestContext)request- current HTTP request- 返回:
- the wrapped or unwrapped value to be rendered
-
writeContent
Write the actual JSON content to the stream.- 参数:
stream- the output stream to useobject- the value to be rendered, as returned fromfilterModel(java.util.Map<java.lang.String, java.lang.Object>)- 抛出:
IOException- if writing failed
-
setModelKey
Set the attribute in the model that should be rendered by this view. When set, all other model attributes will be ignored. -
filterModel
Filter out undesired attributes from the given model. The return value can be either anotherMapor a single value object.- 参数:
model- the model, as passed on torenderMergedOutputModel(java.util.Map<java.lang.String, java.lang.Object>, cn.taketoday.web.RequestContext)- 返回:
- the value to be rendered
-
writePrefix
Write a prefix before the main content.- 参数:
generator- the generator to use for writing content.object- the object to write to the output message.- 抛出:
IOException
-
writeSuffix
Write a suffix after the main content.- 参数:
generator- the generator to use for writing content.object- the object to write to the output message.- 抛出:
IOException
-