public class JacksonObjectMapperFactoryBean extends Object implements org.springframework.beans.factory.FactoryBean<ObjectMapper>, org.springframework.beans.factory.InitializingBean
ObjectMapper
with setters to
enable or disable Jackson features from within XML configuration.
Example usage with MappingJacksonHttpMessageConverter:
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> <property name="objectMapper"> <bean class="org.springframework.web.context.support.JacksonObjectMapperFactoryBean" p:autoDetectFields="false" p:autoDetectGettersSetters="false" p:annotationIntrospector-ref="jaxbAnnotationIntrospector" /> </property> </bean>
Example usage with MappingJacksonJsonView:
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"> <property name="objectMapper"> <bean class="org.springframework.web.context.support.JacksonObjectMapperFactoryBean" p:autoDetectFields="false" p:autoDetectGettersSetters="false" p:annotationIntrospector-ref="jaxbAnnotationIntrospector" /> </property> </bean>
In case there are no specific setters provided (for some rarely used
options), you can still use the more general methods
setFeaturesToEnable(Object[])
and setFeaturesToDisable(Object[])
.
<bean class="org.springframework.web.context.support.JacksonObjectMapperFactoryBean"> <property name="featuresToEnable"> <array> <util:constant static-field="org.codehaus.jackson.map.SerializationConfig$Feature.WRAP_ROOT_VALUE"/> <util:constant static-field="org.codehaus.jackson.map.SerializationConfig$Feature.CLOSE_CLOSEABLE"/> </array> </property> <property name="featuresToDisable"> <array> <util:constant static-field="org.codehaus.jackson.map.DeserializationConfig$Feature.USE_ANNOTATIONS"/> </array> </property> </bean>
Constructor and Description |
---|
JacksonObjectMapperFactoryBean() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
ObjectMapper |
getObject()
Return the singleton ObjectMapper.
|
Class<?> |
getObjectType() |
boolean |
isSingleton() |
void |
setAnnotationIntrospector(AnnotationIntrospector annotationIntrospector)
Set the
AnnotationIntrospector for serialization and deserialization. |
void |
setAutoDetectFields(boolean autoDetectFields)
|
void |
setAutoDetectGettersSetters(boolean autoDetectGettersSetters)
|
void |
setDateFormat(DateFormat dateFormat)
Define the format for date/time with the given
DateFormat . |
void |
setFailOnEmptyBeans(boolean failOnEmptyBeans)
Shortcut for
SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS . |
void |
setFeaturesToDisable(Object[] featuresToDisable)
Specify features to disable.
|
void |
setFeaturesToEnable(Object[] featuresToEnable)
Specify features to enable.
|
void |
setIndentOutput(boolean indentOutput)
Shortcut for
SerializationConfig.Feature.INDENT_OUTPUT . |
void |
setObjectMapper(ObjectMapper objectMapper)
Set the ObjectMapper instance to use.
|
void |
setSimpleDateFormat(String format)
Define the date/time format with a
SimpleDateFormat . |
public void setObjectMapper(ObjectMapper objectMapper)
public void setDateFormat(DateFormat dateFormat)
DateFormat
.setSimpleDateFormat(String)
public void setSimpleDateFormat(String format)
SimpleDateFormat
.setDateFormat(DateFormat)
public void setAnnotationIntrospector(AnnotationIntrospector annotationIntrospector)
AnnotationIntrospector
for serialization and deserialization.public void setAutoDetectFields(boolean autoDetectFields)
public void setAutoDetectGettersSetters(boolean autoDetectGettersSetters)
public void setFailOnEmptyBeans(boolean failOnEmptyBeans)
SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS
.public void setIndentOutput(boolean indentOutput)
SerializationConfig.Feature.INDENT_OUTPUT
.public void setFeaturesToEnable(Object[] featuresToEnable)
public void setFeaturesToDisable(Object[] featuresToDisable)
public void afterPropertiesSet()
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
public ObjectMapper getObject()
getObject
in interface org.springframework.beans.factory.FactoryBean<ObjectMapper>
public Class<?> getObjectType()
getObjectType
in interface org.springframework.beans.factory.FactoryBean<ObjectMapper>
public boolean isSingleton()
isSingleton
in interface org.springframework.beans.factory.FactoryBean<ObjectMapper>