org.springframework.yarn.integration.support
Class Jackson2ObjectMapperFactoryBean

java.lang.Object
  extended by org.springframework.yarn.integration.support.Jackson2ObjectMapperFactoryBean
All Implemented Interfaces:
FactoryBean<com.fasterxml.jackson.databind.ObjectMapper>, InitializingBean

public class Jackson2ObjectMapperFactoryBean
extends Object
implements FactoryBean<com.fasterxml.jackson.databind.ObjectMapper>, InitializingBean

A FactoryBean for creating a Jackson 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.

Author:
Dmitry Katsubo, Rossen Stoyanchev, Janne Valkealahti

Constructor Summary
Jackson2ObjectMapperFactoryBean()
           
 
Method Summary
 void afterPropertiesSet()
           
 com.fasterxml.jackson.databind.ObjectMapper getObject()
          Return the singleton ObjectMapper.
 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(DateFormat dateFormat)
          Define the format for date/time with the given DateFormat.
 void setDeserializersByType(Map<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(Object... featuresToDisable)
          Specify features to disable.
 void setFeaturesToEnable(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(Map<Class<?>,com.fasterxml.jackson.databind.JsonSerializer<?>> serializers)
          Configure custom serializers for the given types.
 void setSimpleDateFormat(String format)
          Define the date/time format with a SimpleDateFormat.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Jackson2ObjectMapperFactoryBean

public Jackson2ObjectMapperFactoryBean()
Method Detail

setObjectMapper

public void setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Set the ObjectMapper instance to use. If not set, the ObjectMapper will be created using its default constructor.

Parameters:
objectMapper - object mapper

setDateFormat

public void setDateFormat(DateFormat dateFormat)
Define the format for date/time with the given DateFormat.

Parameters:
dateFormat - date format
See Also:
setSimpleDateFormat(String)

setSimpleDateFormat

public void setSimpleDateFormat(String format)
Define the date/time format with a SimpleDateFormat.

Parameters:
format - format
See Also:
setDateFormat(DateFormat)

setAnnotationIntrospector

public void setAnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector annotationIntrospector)
Set the AnnotationIntrospector for both serialization and deserialization.

Parameters:
annotationIntrospector - the AnnotationIntrospector

setSerializers

public void setSerializers(com.fasterxml.jackson.databind.JsonSerializer<?>... serializers)
Configure custom serializers. Each serializer is registered for the type returned by JsonSerializer.handledType(), which must not be null.

Parameters:
serializers - serializers
See Also:
setSerializersByType(Map)

setSerializersByType

public void setSerializersByType(Map<Class<?>,com.fasterxml.jackson.databind.JsonSerializer<?>> serializers)
Configure custom serializers for the given types.

Parameters:
serializers - serializers
See Also:
setSerializers(JsonSerializer...)

setDeserializersByType

public void setDeserializersByType(Map<Class<?>,com.fasterxml.jackson.databind.JsonDeserializer<?>> deserializers)
Configure custom deserializers for the given types.

Parameters:
deserializers - deserializers

setAutoDetectFields

public void setAutoDetectFields(boolean autoDetectFields)
Shortcut for MapperFeature.AUTO_DETECT_FIELDS option.

Parameters:
autoDetectFields - autoDetectFields

setAutoDetectGettersSetters

public void setAutoDetectGettersSetters(boolean autoDetectGettersSetters)
Shortcut for MapperFeature.AUTO_DETECT_SETTERS/ MapperFeature.AUTO_DETECT_GETTERS option.

Parameters:
autoDetectGettersSetters - autoDetectGettersSetters

setFailOnEmptyBeans

public void setFailOnEmptyBeans(boolean failOnEmptyBeans)
Shortcut for SerializationFeature.FAIL_ON_EMPTY_BEANS option.

Parameters:
failOnEmptyBeans - failOnEmptyBeans

setIndentOutput

public void setIndentOutput(boolean indentOutput)
Shortcut for SerializationFeature.INDENT_OUTPUT option.

Parameters:
indentOutput - indentOutput

setFeaturesToEnable

public void setFeaturesToEnable(Object... featuresToEnable)
Specify features to enable.

Parameters:
featuresToEnable - featuresToEnable
See Also:
MapperFeature, SerializationFeature, DeserializationFeature, JsonParser.Feature, JsonGenerator.Feature

setFeaturesToDisable

public void setFeaturesToDisable(Object... featuresToDisable)
Specify features to disable.

Parameters:
featuresToDisable - featuresToDisable
See Also:
MapperFeature, SerializationFeature, DeserializationFeature, JsonParser.Feature, JsonGenerator.Feature

afterPropertiesSet

public void afterPropertiesSet()
                        throws FatalBeanException
Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
FatalBeanException

getObject

public com.fasterxml.jackson.databind.ObjectMapper getObject()
Return the singleton ObjectMapper.

Specified by:
getObject in interface FactoryBean<com.fasterxml.jackson.databind.ObjectMapper>
Returns:
object mapper

getObjectType

public Class<?> getObjectType()
Specified by:
getObjectType in interface FactoryBean<com.fasterxml.jackson.databind.ObjectMapper>

isSingleton

public boolean isSingleton()
Specified by:
isSingleton in interface FactoryBean<com.fasterxml.jackson.databind.ObjectMapper>