Class AbstractJacksonView
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.AbstractJacksonView
- All Implemented Interfaces:
- Aware,- BeanNameAware,- ApplicationContextAware,- ServletContextAware,- View
- Direct Known Subclasses:
- JacksonJsonView,- JacksonXmlView
Abstract base class for Jackson 3.x based and content type independent
 
AbstractView implementations.
 The following special model entries are supported:
- A JSON view with a com.fasterxml.jackson.annotation.JsonViewkey and the class name of the JSON view as value.
- A filter provider with a tools.jackson.databind.ser.FilterProviderkey and the filter provider class name as value.
- Since:
- 7.0
- Author:
- Sebastien Deleuze
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected static final Stringprotected static final Stringprotected booleanFields inherited from class org.springframework.web.servlet.view.AbstractViewDEFAULT_CONTENT_TYPEFields inherited from class org.springframework.context.support.ApplicationObjectSupportloggerFields inherited from interface org.springframework.web.servlet.ViewPATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedAbstractJacksonView(MapperBuilder<?, ?> builder, String contentType) protectedAbstractJacksonView(ObjectMapper objectMapper, String contentType) 
- 
Method SummaryModifier and TypeMethodDescriptionprotected abstract ObjectfilterModel(Map<String, Object> model, HttpServletRequest request) Filter out undesired attributes from the given model.final tools.jackson.core.JsonEncodingReturn theJsonEncodingfor this view.protected voidprepareResponse(HttpServletRequest request, HttpServletResponse response) Prepare the given response for rendering.protected voidrenderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) Subclasses must implement this method to actually render the view.voidsetDisableCaching(boolean disableCaching) Disables caching of the generated JSON.voidsetEncoding(tools.jackson.core.JsonEncoding encoding) Set theJsonEncodingfor this view.abstract voidsetModelKey(String modelKey) Set the attribute in the model that should be rendered by this view.voidsetUpdateContentLength(boolean updateContentLength) Whether to update the 'Content-Length' header of the response.protected voidwriteContent(OutputStream stream, Object object, @Nullable Map<String, Object> hints) Write the actual JSON content to the stream.protected voidwritePrefix(tools.jackson.core.JsonGenerator generator, Object object) Write a prefix before the main content.protected voidwriteSuffix(tools.jackson.core.JsonGenerator generator, Object object) Write a suffix after the main content.Methods inherited from class org.springframework.web.servlet.view.AbstractViewaddStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, formatViewName, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getRequestToExpose, getStaticAttributes, isExposePathVariables, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setRequestContextAttribute, setResponseContentType, toString, writeToResponseMethods inherited from class org.springframework.web.context.support.WebApplicationObjectSupportgetServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextMethods inherited from class org.springframework.context.support.ApplicationObjectSupportgetApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext
- 
Field Details- 
JSON_VIEW_HINT
- 
FILTER_PROVIDER_HINT
- 
updateContentLengthprotected boolean updateContentLength
 
- 
- 
Constructor Details- 
AbstractJacksonView
- 
AbstractJacksonView
 
- 
- 
Method Details- 
setEncodingpublic void setEncoding(tools.jackson.core.JsonEncoding encoding) Set theJsonEncodingfor this view.Default is UTF-8. 
- 
getEncodingpublic final tools.jackson.core.JsonEncoding getEncoding()Return theJsonEncodingfor this view.
- 
setDisableCachingpublic void setDisableCaching(boolean disableCaching) Disables caching of the generated JSON.Default is true, which will prevent the client from caching the generated JSON.
- 
setUpdateContentLengthpublic 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.
- 
prepareResponseDescription copied from class:AbstractViewPrepare the given response for rendering.The default implementation applies a workaround for an IE bug when sending download content via HTTPS. - Overrides:
- prepareResponsein class- AbstractView
- Parameters:
- request- current HTTP request
- response- current HTTP response
 
- 
renderMergedOutputModelprotected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws ExceptionDescription copied from class: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. - Specified by:
- renderMergedOutputModelin class- AbstractView
- Parameters:
- model- combined output Map (never- null), with dynamic values taking precedence over static attributes
- request- current HTTP request
- response- current HTTP response
- Throws:
- Exception- if rendering failed
 
- 
writeContentprotected void writeContent(OutputStream stream, Object object, @Nullable Map<String, Object> hints) throws IOExceptionWrite the actual JSON content to the stream.- Parameters:
- stream- the output stream to use
- object- the value to be rendered, as returned from- filterModel(java.util.Map<java.lang.String, java.lang.Object>, jakarta.servlet.http.HttpServletRequest)
- hints- additional information about how to serialize the data
- Throws:
- IOException- if writing failed
 
- 
setModelKeySet the attribute in the model that should be rendered by this view.When set, all other model attributes will be ignored. 
- 
filterModelFilter out undesired attributes from the given model.The return value can be either another Mapor a single value object.- Parameters:
- model- the model, as passed on to- renderMergedOutputModel(java.util.Map<java.lang.String, java.lang.Object>, jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
- request- current HTTP request
- Returns:
- the value to be rendered
 
- 
writePrefixprotected void writePrefix(tools.jackson.core.JsonGenerator generator, Object object) throws IOException Write a prefix before the main content.- Parameters:
- generator- the generator to use for writing content
- object- the object to write to the output message
- Throws:
- IOException
 
- 
writeSuffixprotected void writeSuffix(tools.jackson.core.JsonGenerator generator, Object object) throws IOException Write a suffix after the main content.- Parameters:
- generator- the generator to use for writing content
- object- the object to write to the output message
- Throws:
- IOException
 
 
-