public class Jackson2ObjectMapperFactoryBean
extends java.lang.Object
implements org.springframework.beans.factory.FactoryBean<com.fasterxml.jackson.databind.ObjectMapper>, org.springframework.beans.factory.InitializingBean
ObjectMapper
with setters to
enable or disable Jackson features from within XML configuration.
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.yarn.integration.support.Jackson2ObjectMapperFactoryBean"> <property name="featuresToEnable"> <array> <util:constant static-field="com.fasterxml.jackson.databind.SerializationFeature$WRAP_ROOT_VALUE"/> <util:constant static-field="com.fasterxml.jackson.databind.SerializationFeature$CLOSE_CLOSEABLE"/> </array> </property> <property name="featuresToDisable"> <array> <util:constant static-field="com.fasterxml.jackson.databind.MapperFeature$USE_ANNOTATIONS"/> </array> </property> </bean>
Note: This BeanFctory is singleton, so if you need more than one you'll need to configure multiple instances.
Constructor and Description |
---|
Jackson2ObjectMapperFactoryBean() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
com.fasterxml.jackson.databind.ObjectMapper |
getObject()
Return the singleton ObjectMapper.
|
java.lang.Class<?> |
getObjectType() |
boolean |
isSingleton() |
void |
setAnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector annotationIntrospector)
Set the
AnnotationIntrospector for both serialization and
deserialization. |
void |
setAutoDetectFields(boolean autoDetectFields)
Shortcut for
MapperFeature.AUTO_DETECT_FIELDS option. |
void |
setAutoDetectGettersSetters(boolean autoDetectGettersSetters)
Shortcut for
MapperFeature.AUTO_DETECT_SETTERS /
MapperFeature.AUTO_DETECT_GETTERS option. |
void |
setDateFormat(java.text.DateFormat dateFormat)
Define the format for date/time with the given
DateFormat . |
void |
setDeserializersByType(java.util.Map<java.lang.Class<?>,com.fasterxml.jackson.databind.JsonDeserializer<?>> deserializers)
Configure custom deserializers for the given types.
|
void |
setFailOnEmptyBeans(boolean failOnEmptyBeans)
Shortcut for
SerializationFeature.FAIL_ON_EMPTY_BEANS option. |
void |
setFeaturesToDisable(java.lang.Object... featuresToDisable)
Specify features to disable.
|
void |
setFeaturesToEnable(java.lang.Object... featuresToEnable)
Specify features to enable.
|
void |
setIndentOutput(boolean indentOutput)
Shortcut for
SerializationFeature.INDENT_OUTPUT option. |
void |
setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Set the ObjectMapper instance to use.
|
void |
setSerializers(com.fasterxml.jackson.databind.JsonSerializer<?>... serializers)
Configure custom serializers.
|
void |
setSerializersByType(java.util.Map<java.lang.Class<?>,com.fasterxml.jackson.databind.JsonSerializer<?>> serializers)
Configure custom serializers for the given types.
|
void |
setSimpleDateFormat(java.lang.String format)
Define the date/time format with a
SimpleDateFormat . |
public void setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
objectMapper
- object mapperpublic void setDateFormat(java.text.DateFormat dateFormat)
DateFormat
.dateFormat
- date formatsetSimpleDateFormat(String)
public void setSimpleDateFormat(java.lang.String format)
SimpleDateFormat
.format
- formatsetDateFormat(DateFormat)
public void setAnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector annotationIntrospector)
AnnotationIntrospector
for both serialization and
deserialization.annotationIntrospector
- the AnnotationIntrospectorpublic void setSerializers(com.fasterxml.jackson.databind.JsonSerializer<?>... serializers)
JsonSerializer.handledType()
, which must not be
null
.serializers
- serializerssetSerializersByType(Map)
public void setSerializersByType(java.util.Map<java.lang.Class<?>,com.fasterxml.jackson.databind.JsonSerializer<?>> serializers)
serializers
- serializerssetSerializers(JsonSerializer...)
public void setDeserializersByType(java.util.Map<java.lang.Class<?>,com.fasterxml.jackson.databind.JsonDeserializer<?>> deserializers)
deserializers
- deserializerspublic void setAutoDetectFields(boolean autoDetectFields)
MapperFeature.AUTO_DETECT_FIELDS
option.autoDetectFields
- autoDetectFieldspublic void setAutoDetectGettersSetters(boolean autoDetectGettersSetters)
MapperFeature.AUTO_DETECT_SETTERS
/
MapperFeature.AUTO_DETECT_GETTERS
option.autoDetectGettersSetters
- autoDetectGettersSetterspublic void setFailOnEmptyBeans(boolean failOnEmptyBeans)
SerializationFeature.FAIL_ON_EMPTY_BEANS
option.failOnEmptyBeans
- failOnEmptyBeanspublic void setIndentOutput(boolean indentOutput)
SerializationFeature.INDENT_OUTPUT
option.indentOutput
- indentOutputpublic void setFeaturesToEnable(java.lang.Object... featuresToEnable)
featuresToEnable
- featuresToEnableMapperFeature
,
SerializationFeature
,
DeserializationFeature
,
JsonParser.Feature
,
JsonGenerator.Feature
public void setFeaturesToDisable(java.lang.Object... featuresToDisable)
featuresToDisable
- featuresToDisableMapperFeature
,
SerializationFeature
,
DeserializationFeature
,
JsonParser.Feature
,
JsonGenerator.Feature
public void afterPropertiesSet() throws org.springframework.beans.FatalBeanException
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
org.springframework.beans.FatalBeanException
public com.fasterxml.jackson.databind.ObjectMapper getObject()
getObject
in interface org.springframework.beans.factory.FactoryBean<com.fasterxml.jackson.databind.ObjectMapper>
public java.lang.Class<?> getObjectType()
getObjectType
in interface org.springframework.beans.factory.FactoryBean<com.fasterxml.jackson.databind.ObjectMapper>
public boolean isSingleton()
isSingleton
in interface org.springframework.beans.factory.FactoryBean<com.fasterxml.jackson.databind.ObjectMapper>