Class AbstractJackson2View

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.json.AbstractJackson2View
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.context.ApplicationContextAware, org.springframework.web.context.ServletContextAware, View
Direct Known Subclasses:
MappingJackson2JsonView, MappingJackson2XmlView

@Deprecated(since="7.0", forRemoval=true) public abstract class AbstractJackson2View extends AbstractView
Deprecated, for removal: This API element is subject to removal in a future version.
since 7.0 in favor of AbstractJacksonView
Abstract base class for Jackson 2.x based and content type independent AbstractView implementations.
Since:
4.1
Author:
Jeremy Grelle, Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller, Sebastien Deleuze
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
     

    Fields inherited from class AbstractView

    DEFAULT_CONTENT_TYPE

    Fields inherited from class org.springframework.context.support.ApplicationObjectSupport

    logger
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractJackson2View(com.fasterxml.jackson.databind.ObjectMapper objectMapper, String contentType)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Object
    filterAndWrapModel(Map<String,Object> model, jakarta.servlet.http.HttpServletRequest request)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Filter and optionally wrap the model in MappingJacksonValue container.
    protected abstract Object
    Deprecated, for removal: This API element is subject to removal in a future version.
    Filter out undesired attributes from the given model.
    final com.fasterxml.jackson.core.JsonEncoding
    Deprecated, for removal: This API element is subject to removal in a future version.
    Return the JsonEncoding for this view.
    final com.fasterxml.jackson.databind.ObjectMapper
    Deprecated, for removal: This API element is subject to removal in a future version.
    Return the ObjectMapper for this view.
    protected void
    prepareResponse(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Prepare the given response for rendering.
    protected void
    renderMergedOutputModel(Map<String,Object> model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Subclasses must implement this method to actually render the view.
    void
    setDisableCaching(boolean disableCaching)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Disables caching of the generated JSON.
    void
    setEncoding(com.fasterxml.jackson.core.JsonEncoding encoding)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set the JsonEncoding for this view.
    abstract void
    setModelKey(String modelKey)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set the attribute in the model that should be rendered by this view.
    void
    setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set the ObjectMapper for this view.
    void
    setPrettyPrint(boolean prettyPrint)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Whether to use the default pretty printer when writing the output.
    void
    setUpdateContentLength(boolean updateContentLength)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Whether to update the 'Content-Length' header of the response.
    protected void
    writeContent(OutputStream stream, Object object)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Write the actual JSON content to the stream.
    protected void
    writePrefix(com.fasterxml.jackson.core.JsonGenerator generator, Object object)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Write a prefix before the main content.
    protected void
    writeSuffix(com.fasterxml.jackson.core.JsonGenerator generator, Object object)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Write a suffix after the main content.

    Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport

    getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext

    Methods inherited from class org.springframework.context.support.ApplicationObjectSupport

    getApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • updateContentLength

      protected boolean updateContentLength
      Deprecated, for removal: This API element is subject to removal in a future version.
  • Constructor Details

    • AbstractJackson2View

      protected AbstractJackson2View(com.fasterxml.jackson.databind.ObjectMapper objectMapper, String contentType)
      Deprecated, for removal: This API element is subject to removal in a future version.
  • Method Details

    • setObjectMapper

      public void setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the ObjectMapper for this view. If not set, a default ObjectMapper will be used.

      Setting a custom-configured ObjectMapper is 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

      public final com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Return the ObjectMapper for this view.
    • setEncoding

      public void setEncoding(com.fasterxml.jackson.core.JsonEncoding encoding)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the JsonEncoding for this view. By default, UTF-8 is used.
    • getEncoding

      public final com.fasterxml.jackson.core.JsonEncoding getEncoding()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Return the JsonEncoding for this view.
    • setPrettyPrint

      public void setPrettyPrint(boolean prettyPrint)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Whether to use the default pretty printer when writing the output. This is a shortcut for setting up an ObjectMapper as follows:
      ObjectMapper mapper = new ObjectMapper();
      mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
      

      The default value is false.

    • setDisableCaching

      public void setDisableCaching(boolean disableCaching)
      Deprecated, for removal: This API element is subject to removal in a future version.
      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)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Whether to update the 'Content-Length' header of the response. When set to true, 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

      protected void prepareResponse(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Description copied from class: AbstractView
      Prepare the given response for rendering.

      The default implementation applies a workaround for an IE bug when sending download content via HTTPS.

      Overrides:
      prepareResponse in class AbstractView
      Parameters:
      request - current HTTP request
      response - current HTTP response
    • renderMergedOutputModel

      protected void renderMergedOutputModel(Map<String,Object> model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws Exception
      Deprecated, for removal: This API element is subject to removal in a future version.
      Description copied from class: AbstractView
      Subclasses 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:
      renderMergedOutputModel in 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
    • filterAndWrapModel

      protected Object filterAndWrapModel(Map<String,Object> model, jakarta.servlet.http.HttpServletRequest request)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Filter and optionally wrap the model in MappingJacksonValue container.
      Parameters:
      model - the model, as passed on to renderMergedOutputModel(Map, HttpServletRequest, HttpServletResponse)
      request - current HTTP request
      Returns:
      the wrapped or unwrapped value to be rendered
    • writeContent

      protected void writeContent(OutputStream stream, Object object) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Write the actual JSON content to the stream.
      Parameters:
      stream - the output stream to use
      object - the value to be rendered, as returned from filterModel(Map)
      Throws:
      IOException - if writing failed
    • setModelKey

      public abstract void setModelKey(String modelKey)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the attribute in the model that should be rendered by this view. When set, all other model attributes will be ignored.
    • filterModel

      protected abstract Object filterModel(Map<String,Object> model)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Filter out undesired attributes from the given model. The return value can be either another Map or a single value object.
      Parameters:
      model - the model, as passed on to renderMergedOutputModel(Map, HttpServletRequest, HttpServletResponse)
      Returns:
      the value to be rendered
    • writePrefix

      protected void writePrefix(com.fasterxml.jackson.core.JsonGenerator generator, Object object) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      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
    • writeSuffix

      protected void writeSuffix(com.fasterxml.jackson.core.JsonGenerator generator, Object object) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      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