Spring for Apache Hadoop

org.springframework.yarn.integration.support
Class Jackson2ObjectMapperFactoryBean

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

public class Jackson2ObjectMapperFactoryBean
extends java.lang.Object
implements org.springframework.beans.factory.FactoryBean<com.fasterxml.jackson.databind.ObjectMapper>, org.springframework.beans.factory.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.
 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.
 
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.


setDateFormat

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

See Also:
setSimpleDateFormat(String)

setSimpleDateFormat

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

See Also:
setDateFormat(DateFormat)

setAnnotationIntrospector

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


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.

See Also:
setSerializersByType(Map)

setSerializersByType

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

See Also:
setSerializers(JsonSerializer...)

setDeserializersByType

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


setAutoDetectFields

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


setAutoDetectGettersSetters

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


setFailOnEmptyBeans

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


setIndentOutput

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


setFeaturesToEnable

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

See Also:
MapperFeature, SerializationFeature, DeserializationFeature, JsonParser.Feature, JsonGenerator.Feature

setFeaturesToDisable

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

See Also:
MapperFeature, SerializationFeature, DeserializationFeature, JsonParser.Feature, JsonGenerator.Feature

afterPropertiesSet

public void afterPropertiesSet()
                        throws org.springframework.beans.FatalBeanException
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
org.springframework.beans.FatalBeanException

getObject

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

Specified by:
getObject in interface org.springframework.beans.factory.FactoryBean<com.fasterxml.jackson.databind.ObjectMapper>

getObjectType

public java.lang.Class<?> getObjectType()
Specified by:
getObjectType in interface org.springframework.beans.factory.FactoryBean<com.fasterxml.jackson.databind.ObjectMapper>

isSingleton

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

Spring for Apache Hadoop