Package org.springframework.web.servlet.view.xml

# Class MappingJackson2XmlView

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
org.springframework.web.servlet.view.xml.MappingJackson2XmlView

All Implemented Interfaces:
  `org.springframework.beans.factory.Aware`, `org.springframework.beans.factory.BeanNameAware`, `org.springframework.context.ApplicationContextAware`, `org.springframework.web.context.ServletContextAware`, `View`

public class MappingJackson2XmlView extends AbstractJackson2View
Spring MVC `View` that renders XML content by serializing the model for the current request using Jackson 2's `XmlMapper`.

The Object to be serialized is supplied as a parameter in the model. The first serializable entry is used. Users can either specify a specific entry in the model via the `sourceKey` property.

The default constructor uses the default configuration provided by `Jackson2ObjectMapperBuilder`.

Since:
  4.1
Author:
  Sebastien Deleuze
See Also:
  - `MappingJackson2JsonView`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`DEFAULT_CONTENT_TYPE`
The default content type for the view.

### Fields inherited from class org.springframework.web.servlet.view.json.AbstractJackson2View

`updateContentLength`

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

`logger`

### Fields inherited from interface org.springframework.web.servlet.View

`PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE`

## Constructor Summary

Constructors
Constructor
Description
`MappingJackson2XmlView()`
Construct a new `MappingJackson2XmlView` using default configuration provided by `Jackson2ObjectMapperBuilder` and setting the content type to `application/xml`.
`MappingJackson2XmlView(XmlMapper xmlMapper)`
Construct a new `MappingJackson2XmlView` using the provided `XmlMapper` and setting the content type to `application/xml`.

## Method Summary

Modifier and Type
Method
Description
`protected Object`
`filterModel(Map<String,Object> model)`
Filter out undesired attributes from the given model.
`void`
`setModelKey(String modelKey)`
Set the attribute in the model that should be rendered by this view.

### Methods inherited from class org.springframework.web.servlet.view.json.AbstractJackson2View

`filterAndWrapModel, getEncoding, getObjectMapper, prepareResponse, renderMergedOutputModel, setDisableCaching, setEncoding, setObjectMapper, setPrettyPrint, setUpdateContentLength, writeContent, writePrefix, writeSuffix`

### Methods inherited from class org.springframework.web.servlet.view.AbstractView

`addStaticAttribute, 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, writeToResponse`

### 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 java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Field Details

### DEFAULT_CONTENT_TYPE

public static final String DEFAULT_CONTENT_TYPE
The default content type for the view.

See Also:
  - Constant Field Values

## Constructor Details

### MappingJackson2XmlView

public MappingJackson2XmlView()
Construct a new `MappingJackson2XmlView` using default configuration provided by `Jackson2ObjectMapperBuilder` and setting the content type to `application/xml`.

### MappingJackson2XmlView

public MappingJackson2XmlView(XmlMapper xmlMapper)
Construct a new `MappingJackson2XmlView` using the provided `XmlMapper` and setting the content type to `application/xml`.

Since:
  4.2.1

## Method Details

### setModelKey

public void setModelKey(String modelKey)
Description copied from class: `AbstractJackson2View`
Set the attribute in the model that should be rendered by this view. When set, all other model attributes will be ignored.

Specified by:
  `setModelKey` in class `AbstractJackson2View`

### filterModel

protected Object filterModel(Map<String,Object> model)
Description copied from class: `AbstractJackson2View`
Filter out undesired attributes from the given model. The return value can be either another `Map` or a single value object.

Specified by:
  `filterModel` in class `AbstractJackson2View`
Parameters:
  `model` - the model, as passed on to `AbstractJackson2View.renderMergedOutputModel(java.util.Map<java.lang.String, java.lang.Object>, jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)`
Returns:
  the value to be rendered