org.codehaus.jackson.map
Class SerializationConfig

java.lang.Object
  extended by org.codehaus.jackson.map.MapperConfig<SerializationConfig>
      extended by org.codehaus.jackson.map.SerializationConfig
All Implemented Interfaces:
ClassIntrospector.MixInResolver

public class SerializationConfig
extends MapperConfig<SerializationConfig>

Object that contains baseline configuration for serialization process. An instance is owned by ObjectMapper, which makes a copy that is passed during serialization process to SerializerProvider and SerializerFactory.

Note: although configuration settings can be changed at any time (for factories and instances), they are not guaranteed to have effect if called after constructing relevant mapper or serializer instance. This because some objects may be configured, constructed and cached first time they are needed.


Nested Class Summary
static class SerializationConfig.Feature
          Enumeration that defines togglable features that guide the serialization feature.
 
Nested classes/interfaces inherited from class org.codehaus.jackson.map.MapperConfig
MapperConfig.Base
 
Field Summary
protected  int _featureFlags
           
protected  FilterProvider _filterProvider
          Object used for resolving filter ids to filter instances.
protected  JsonSerialize.Inclusion _serializationInclusion
          Which Bean/Map properties are to be included in serialization? Default settings is to include all regardless of value; can be changed to only include non-null properties, or properties with non-default values.
protected  Class<?> _serializationView
          View to use for filtering out properties to serialize.
protected static int DEFAULT_FEATURE_FLAGS
          Bitfield (set of flags) of all Features that are enabled by default.
 
Fields inherited from class org.codehaus.jackson.map.MapperConfig
_base, _mixInAnnotations, _mixInAnnotationsShared, _subtypeResolver, DEFAULT_DATE_FORMAT
 
Constructor Summary
  SerializationConfig(ClassIntrospector<? extends BeanDescription> intr, AnnotationIntrospector annIntr, VisibilityChecker<?> vc, SubtypeResolver subtypeResolver, PropertyNamingStrategy propertyNamingStrategy, TypeFactory typeFactory, HandlerInstantiator handlerInstantiator)
          Constructor used by ObjectMapper to create default configuration object instance.
protected SerializationConfig(SerializationConfig src)
           
protected SerializationConfig(SerializationConfig src, Class<?> view)
           
protected SerializationConfig(SerializationConfig src, FilterProvider filters)
           
protected SerializationConfig(SerializationConfig src, HashMap<ClassKey,Class<?>> mixins, SubtypeResolver str)
          Constructor used to make a private copy of specific mix-in definitions.
protected SerializationConfig(SerializationConfig src, MapperConfig.Base base)
           
 
Method Summary
 boolean canOverrideAccessModifiers()
          Accessor for determining whether it is ok to try to force override of access modifiers to be able to get or set values of non-public Methods, Fields; to invoke non-public Constructors, Methods; or to instantiate non-public Classes.
 SerializationConfig createUnshared(SubtypeResolver subtypeResolver)
          Method to use for constructing an instance that is not shared between multiple operations but only used for a single one (which may be this instance, if it is immutable; if not, a copy is constructed with same settings)
 SerializationConfig createUnshared(TypeResolverBuilder<?> typer, VisibilityChecker<?> vc, SubtypeResolver str)
          Deprecated. Since 1.8 should use variant without arguments
 void disable(SerializationConfig.Feature f)
          Method for disabling specified feature.
 void enable(SerializationConfig.Feature f)
          Method for enabling specified feature.
 void fromAnnotations(Class<?> cls)
          Method that checks class annotations that the argument Object has, and modifies settings of this configuration object accordingly, similar to how those annotations would affect actual value classes annotated with them, but with global scope.
 AnnotationIntrospector getAnnotationIntrospector()
          Method for getting AnnotationIntrospector configured to introspect annotation values used for configuration.
 FilterProvider getFilterProvider()
          Method for getting provider used for locating filters given id (which is usually provided with filter annotations).
 JsonSerialize.Inclusion getSerializationInclusion()
           
 Class<?> getSerializationView()
          Method for checking which serialization view is being used, if any; null if none.
<T extends BeanDescription>
T
introspect(JavaType type)
          Method that will introspect full bean properties for the purpose of building a bean serializer
<T extends BeanDescription>
T
introspectClassAnnotations(Class<?> cls)
          Accessor for getting bean description that only contains class annotations: useful if no getter/setter/creator information is needed.
<T extends BeanDescription>
T
introspectDirectClassAnnotations(Class<?> cls)
          Accessor for getting bean description that only contains immediate class annotations: ones from the class, and its direct mix-in, if any, but not from super types.
 boolean isAnnotationProcessingEnabled()
          Method for determining whether annotation processing is enabled or not (default settings are typically that it is enabled; must explicitly disable).
 boolean isEnabled(SerializationConfig.Feature f)
          Method for checking whether given feature is enabled or not
 JsonSerializer<Object> serializerInstance(Annotated annotated, Class<? extends JsonSerializer<?>> serClass)
           
 void set(SerializationConfig.Feature f, boolean state)
          Method for enabling or disabling specified feature.
 void setDateFormat(DateFormat df)
          Deprecated. Since 1.8, use withDateFormat(java.text.DateFormat) instead.
 void setSerializationInclusion(JsonSerialize.Inclusion props)
          Method that will define global setting of which bean/map properties are to be included in serialization.
 void setSerializationView(Class<?> view)
          Deprecated. Since 1.8, use withView(java.lang.Class) instead
 String toString()
           
 SerializationConfig withAnnotationIntrospector(AnnotationIntrospector ai)
          Method for constructing and returning a new instance with different AnnotationIntrospector to use (replacing old one).
 SerializationConfig withClassIntrospector(ClassIntrospector<? extends BeanDescription> ci)
          Method for constructing and returning a new instance with different ClassIntrospector to use.
 SerializationConfig withDateFormat(DateFormat df)
          In addition to constructing instance with specified date format, will enable or disable Feature.WRITE_DATES_AS_TIMESTAMPS (enable if format set as null; disable if non-null)
 SerializationConfig withFilters(FilterProvider filterProvider)
           
 SerializationConfig withHandlerInstantiator(HandlerInstantiator hi)
          Method for constructing and returning a new instance with different HandlerInstantiator to use.
 SerializationConfig withPropertyNamingStrategy(PropertyNamingStrategy pns)
          Method for constructing and returning a new instance with different PropertyNamingStrategy to use.
 SerializationConfig withSubtypeResolver(SubtypeResolver str)
          Method for constructing and returning a new instance with different SubtypeResolver to use.
 SerializationConfig withTypeFactory(TypeFactory tf)
          Method for constructing and returning a new instance with different TypeFactory to use.
 SerializationConfig withTypeResolverBuilder(TypeResolverBuilder<?> trb)
          Method for constructing and returning a new instance with different TypeResolverBuilder to use.
 SerializationConfig withView(Class<?> view)
           
 SerializationConfig withVisibilityChecker(VisibilityChecker<?> vc)
          Method for constructing and returning a new instance with different VisibilityChecker to use.
 
Methods inherited from class org.codehaus.jackson.map.MapperConfig
addMixInAnnotations, appendAnnotationIntrospector, constructType, findMixInClassFor, getClassIntrospector, getDateFormat, getDefaultTyper, getDefaultVisibilityChecker, getHandlerInstantiator, getPropertyNamingStrategy, getSubtypeResolver, getTypeFactory, insertAnnotationIntrospector, mixInCount, setAnnotationIntrospector, setIntrospector, setMixInAnnotations, setSubtypeResolver, typeIdResolverInstance, typeResolverBuilderInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_FEATURE_FLAGS

protected static final int DEFAULT_FEATURE_FLAGS
Bitfield (set of flags) of all Features that are enabled by default.


_featureFlags

protected int _featureFlags

_serializationInclusion

protected JsonSerialize.Inclusion _serializationInclusion
Which Bean/Map properties are to be included in serialization? Default settings is to include all regardless of value; can be changed to only include non-null properties, or properties with non-default values.

Defaults to null for backwards compatibility; if left as null, will check deprecated SerializationConfig.Feature.WRITE_NULL_PROPERTIES to choose between JsonSerialize.Inclusion.ALWAYS and JsonSerialize.Inclusion.NON_NULL.


_serializationView

protected Class<?> _serializationView
View to use for filtering out properties to serialize. Null if none (will also be assigned null if Object.class is defined), meaning that all properties are to be included.


_filterProvider

protected FilterProvider _filterProvider
Object used for resolving filter ids to filter instances. Non-null if explicitly defined; null by default.

Since:
1.7
Constructor Detail

SerializationConfig

public SerializationConfig(ClassIntrospector<? extends BeanDescription> intr,
                           AnnotationIntrospector annIntr,
                           VisibilityChecker<?> vc,
                           SubtypeResolver subtypeResolver,
                           PropertyNamingStrategy propertyNamingStrategy,
                           TypeFactory typeFactory,
                           HandlerInstantiator handlerInstantiator)
Constructor used by ObjectMapper to create default configuration object instance.


SerializationConfig

protected SerializationConfig(SerializationConfig src)
Since:
1.8

SerializationConfig

protected SerializationConfig(SerializationConfig src,
                              HashMap<ClassKey,Class<?>> mixins,
                              SubtypeResolver str)
Constructor used to make a private copy of specific mix-in definitions.

Since:
1.8

SerializationConfig

protected SerializationConfig(SerializationConfig src,
                              MapperConfig.Base base)
Since:
1.8

SerializationConfig

protected SerializationConfig(SerializationConfig src,
                              FilterProvider filters)
Since:
1.8

SerializationConfig

protected SerializationConfig(SerializationConfig src,
                              Class<?> view)
Since:
1.8
Method Detail

withClassIntrospector

public SerializationConfig withClassIntrospector(ClassIntrospector<? extends BeanDescription> ci)
Description copied from class: MapperConfig
Method for constructing and returning a new instance with different ClassIntrospector to use.

NOTE: make sure to register new instance with ObjectMapper if directly calling this method.

Specified by:
withClassIntrospector in class MapperConfig<SerializationConfig>

withAnnotationIntrospector

public SerializationConfig withAnnotationIntrospector(AnnotationIntrospector ai)
Description copied from class: MapperConfig
Method for constructing and returning a new instance with different AnnotationIntrospector to use (replacing old one).

NOTE: make sure to register new instance with ObjectMapper if directly calling this method.

Specified by:
withAnnotationIntrospector in class MapperConfig<SerializationConfig>

withVisibilityChecker

public SerializationConfig withVisibilityChecker(VisibilityChecker<?> vc)
Description copied from class: MapperConfig
Method for constructing and returning a new instance with different VisibilityChecker to use.

NOTE: make sure to register new instance with ObjectMapper if directly calling this method.

Specified by:
withVisibilityChecker in class MapperConfig<SerializationConfig>

withTypeResolverBuilder

public SerializationConfig withTypeResolverBuilder(TypeResolverBuilder<?> trb)
Description copied from class: MapperConfig
Method for constructing and returning a new instance with different TypeResolverBuilder to use.

NOTE: make sure to register new instance with ObjectMapper if directly calling this method.

Specified by:
withTypeResolverBuilder in class MapperConfig<SerializationConfig>

withSubtypeResolver

public SerializationConfig withSubtypeResolver(SubtypeResolver str)
Description copied from class: MapperConfig
Method for constructing and returning a new instance with different SubtypeResolver to use.

NOTE: make sure to register new instance with ObjectMapper if directly calling this method.

Specified by:
withSubtypeResolver in class MapperConfig<SerializationConfig>

withPropertyNamingStrategy

public SerializationConfig withPropertyNamingStrategy(PropertyNamingStrategy pns)
Description copied from class: MapperConfig
Method for constructing and returning a new instance with different PropertyNamingStrategy to use.

NOTE: make sure to register new instance with ObjectMapper if directly calling this method.

Specified by:
withPropertyNamingStrategy in class MapperConfig<SerializationConfig>

withTypeFactory

public SerializationConfig withTypeFactory(TypeFactory tf)
Description copied from class: MapperConfig
Method for constructing and returning a new instance with different TypeFactory to use.

NOTE: make sure to register new instance with ObjectMapper if directly calling this method.

Specified by:
withTypeFactory in class MapperConfig<SerializationConfig>

withDateFormat

public SerializationConfig withDateFormat(DateFormat df)
In addition to constructing instance with specified date format, will enable or disable Feature.WRITE_DATES_AS_TIMESTAMPS (enable if format set as null; disable if non-null)

Specified by:
withDateFormat in class MapperConfig<SerializationConfig>

withHandlerInstantiator

public SerializationConfig withHandlerInstantiator(HandlerInstantiator hi)
Description copied from class: MapperConfig
Method for constructing and returning a new instance with different HandlerInstantiator to use.

NOTE: make sure to register new instance with ObjectMapper if directly calling this method.

Specified by:
withHandlerInstantiator in class MapperConfig<SerializationConfig>

withFilters

public SerializationConfig withFilters(FilterProvider filterProvider)
Since:
1.7

withView

public SerializationConfig withView(Class<?> view)
Since:
1.8

fromAnnotations

public void fromAnnotations(Class<?> cls)
Method that checks class annotations that the argument Object has, and modifies settings of this configuration object accordingly, similar to how those annotations would affect actual value classes annotated with them, but with global scope. Note that not all annotations have global significance, and thus only subset of Jackson annotations will have any effect.

Serialization annotations that are known to have effect are:

Specified by:
fromAnnotations in class MapperConfig<SerializationConfig>
Parameters:
cls - Class of which class annotations to use for changing configuration settings

createUnshared

public SerializationConfig createUnshared(SubtypeResolver subtypeResolver)
Description copied from class: MapperConfig
Method to use for constructing an instance that is not shared between multiple operations but only used for a single one (which may be this instance, if it is immutable; if not, a copy is constructed with same settings)

Specified by:
createUnshared in class MapperConfig<SerializationConfig>

getAnnotationIntrospector

public AnnotationIntrospector getAnnotationIntrospector()
Description copied from class: MapperConfig
Method for getting AnnotationIntrospector configured to introspect annotation values used for configuration.

Non-final since it is actually overridden by sub-classes (for now?)

Overrides:
getAnnotationIntrospector in class MapperConfig<SerializationConfig>

introspectClassAnnotations

public <T extends BeanDescription> T introspectClassAnnotations(Class<?> cls)
Accessor for getting bean description that only contains class annotations: useful if no getter/setter/creator information is needed.

Note: part of MapperConfig since 1.7

Specified by:
introspectClassAnnotations in class MapperConfig<SerializationConfig>

introspectDirectClassAnnotations

public <T extends BeanDescription> T introspectDirectClassAnnotations(Class<?> cls)
Accessor for getting bean description that only contains immediate class annotations: ones from the class, and its direct mix-in, if any, but not from super types.

Note: part of MapperConfig since 1.7

Specified by:
introspectDirectClassAnnotations in class MapperConfig<SerializationConfig>

isAnnotationProcessingEnabled

public boolean isAnnotationProcessingEnabled()
Description copied from class: MapperConfig
Method for determining whether annotation processing is enabled or not (default settings are typically that it is enabled; must explicitly disable).

Specified by:
isAnnotationProcessingEnabled in class MapperConfig<SerializationConfig>
Returns:
True if annotation processing is enabled; false if not

canOverrideAccessModifiers

public boolean canOverrideAccessModifiers()
Description copied from class: MapperConfig
Accessor for determining whether it is ok to try to force override of access modifiers to be able to get or set values of non-public Methods, Fields; to invoke non-public Constructors, Methods; or to instantiate non-public Classes. By default this is enabled, but on some platforms it needs to be prevented since if this would violate security constraints and cause failures.

Specified by:
canOverrideAccessModifiers in class MapperConfig<SerializationConfig>
Returns:
True if access modifier overriding is allowed (and may be done for any Field, Method, Constructor or Class); false to prevent any attempts to override.

enable

public void enable(SerializationConfig.Feature f)
Method for enabling specified feature.


disable

public void disable(SerializationConfig.Feature f)
Method for disabling specified feature.


set

public void set(SerializationConfig.Feature f,
                boolean state)
Method for enabling or disabling specified feature.


isEnabled

public final boolean isEnabled(SerializationConfig.Feature f)
Method for checking whether given feature is enabled or not


getSerializationView

public Class<?> getSerializationView()
Method for checking which serialization view is being used, if any; null if none.

Since:
1.4

getSerializationInclusion

public JsonSerialize.Inclusion getSerializationInclusion()

setSerializationInclusion

public void setSerializationInclusion(JsonSerialize.Inclusion props)
Method that will define global setting of which bean/map properties are to be included in serialization. Can be overridden by class annotations (overriding settings to use for instances of that class) and method/field annotations (overriding settings for the value bean for that getter method or field)


getFilterProvider

public FilterProvider getFilterProvider()
Method for getting provider used for locating filters given id (which is usually provided with filter annotations). Will be null if no provided was set for ObjectWriter (or if serialization directly called from ObjectMapper)

Since:
1.7

introspect

public <T extends BeanDescription> T introspect(JavaType type)
Method that will introspect full bean properties for the purpose of building a bean serializer


serializerInstance

public JsonSerializer<Object> serializerInstance(Annotated annotated,
                                                 Class<? extends JsonSerializer<?>> serClass)

createUnshared

@Deprecated
public SerializationConfig createUnshared(TypeResolverBuilder<?> typer,
                                                     VisibilityChecker<?> vc,
                                                     SubtypeResolver str)
Deprecated. Since 1.8 should use variant without arguments

Specified by:
createUnshared in class MapperConfig<SerializationConfig>

setDateFormat

@Deprecated
public final void setDateFormat(DateFormat df)
Deprecated. Since 1.8, use withDateFormat(java.text.DateFormat) instead.

One thing to note is that this will set SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS to false (if null format set), or true (if non-null format)

Overrides:
setDateFormat in class MapperConfig<SerializationConfig>

setSerializationView

@Deprecated
public void setSerializationView(Class<?> view)
Deprecated. Since 1.8, use withView(java.lang.Class) instead

Method for checking which serialization view is being used, if any; null if none.

Since:
1.4

toString

public String toString()
Overrides:
toString in class Object