Jackson2ObjectMapperFactoryBean
for Jackson 2.x.@Deprecated public class JacksonObjectMapperFactoryBean extends Object implements org.springframework.beans.factory.FactoryBean<ObjectMapper>, org.springframework.beans.factory.InitializingBean
FactoryBean
for creating a Jackson 1.x 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>
NOTE: Requires Jackson 1.8 or higher, as of Spring 4.0. At the same time, we strongly recommend a migration to Jackson 2.x!
Constructor and Description |
---|
JacksonObjectMapperFactoryBean()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Deprecated.
|
ObjectMapper |
getObject()
Deprecated.
Return the singleton ObjectMapper.
|
Class<?> |
getObjectType()
Deprecated.
|
boolean |
isSingleton()
Deprecated.
|
void |
setAnnotationIntrospector(AnnotationIntrospector annotationIntrospector)
Deprecated.
Set the
AnnotationIntrospector for serialization and deserialization. |
void |
setAutoDetectFields(boolean autoDetectFields)
Deprecated.
|
void |
setAutoDetectGettersSetters(boolean autoDetectGettersSetters)
Deprecated.
|
void |
setDateFormat(DateFormat dateFormat)
Deprecated.
Define the format for date/time with the given
DateFormat . |
void |
setFailOnEmptyBeans(boolean failOnEmptyBeans)
Deprecated.
Shortcut for
SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS . |
void |
setFeaturesToDisable(Object[] featuresToDisable)
Deprecated.
Specify features to disable.
|
void |
setFeaturesToEnable(Object[] featuresToEnable)
Deprecated.
Specify features to enable.
|
void |
setIndentOutput(boolean indentOutput)
Deprecated.
Shortcut for
SerializationConfig.Feature.INDENT_OUTPUT . |
void |
setObjectMapper(ObjectMapper objectMapper)
Deprecated.
Set the ObjectMapper instance to use.
|
void |
setSimpleDateFormat(String format)
Deprecated.
Define the date/time format with a
SimpleDateFormat . |
public JacksonObjectMapperFactoryBean()
public void setObjectMapper(ObjectMapper objectMapper)
public void setDateFormat(DateFormat dateFormat)
DateFormat
.
Note: Setting this property makes the exposed ObjectMapper
non-thread-safe, according to Jackson's thread safety rules.
setSimpleDateFormat(String)
public void setSimpleDateFormat(String format)
SimpleDateFormat
.
Note: Setting this property makes the exposed ObjectMapper
non-thread-safe, according to Jackson's thread safety rules.
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>