org.codehaus.jackson.map
Class SerializationConfig

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

public class SerializationConfig
extends Object
implements 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.
 
Field Summary
protected  AnnotationIntrospector _annotationIntrospector
          Introspector used for accessing annotation value based configuration.
protected  ClassIntrospector<? extends BeanDescription> _classIntrospector
          Introspector used to figure out Bean properties needed for bean serialization and deserialization.
protected  DateFormat _dateFormat
          Textual date format to use for serialization (if enabled by SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS being set to false).
protected  int _featureFlags
           
protected  HashMap<ClassKey,Class<?>> _mixInAnnotations
          Mapping that defines how to apply mix-in annotations: key is the type to received additional annotations, and value is the type that has annotations to "mix in".
protected  boolean _mixInAnnotationsShared
          Flag used to detect when a copy if mix-in annotations is needed: set when current copy is shared, cleared when a fresh copy is maed
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  SubtypeResolver _subtypeResolver
          Registered concrete subtypes that can be used instead of (or in addition to) ones declared using annotations.
protected  TypeResolverBuilder<?> _typer
          Type information handler used for "untyped" values (ones declared to have type Object.class)
protected  VisibilityChecker<?> _visibilityChecker
          Object used for determining whether specific property elements (method, constructors, fields) can be auto-detected based on their visibility (access modifiers).
protected static int DEFAULT_FEATURE_FLAGS
          Bitfield (set of flags) of all Features that are enabled by default.
 
Constructor Summary
  SerializationConfig(ClassIntrospector<? extends BeanDescription> intr, AnnotationIntrospector annIntr, VisibilityChecker<?> vc, SubtypeResolver subtypeResolver)
           
protected SerializationConfig(SerializationConfig src, HashMap<ClassKey,Class<?>> mixins, TypeResolverBuilder<?> typer, VisibilityChecker<?> vc, SubtypeResolver subtypeResolver)
           
 
Method Summary
 void addMixInAnnotations(Class<?> target, Class<?> mixinSource)
          Method to use for adding mix-in annotations to use for augmenting specified class or interface.
 SerializationConfig createUnshared(TypeResolverBuilder<?> typer, VisibilityChecker<?> vc, SubtypeResolver subtypeResolver)
          Method that is called to create a non-shared copy of the configuration to be used for a serialization operation.
 void disable(SerializationConfig.Feature f)
          Method for disabling specified feature.
 void enable(SerializationConfig.Feature f)
          Method for enabling specified feature.
 Class<?> findMixInClassFor(Class<?> cls)
          Method that will check if there are "mix-in" classes (with mix-in annotations) for given class
 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.
 DateFormat getDateFormat()
          Method for accessing currently configured (textual) date format that will be used for reading or writing date values (in case of writing, only if textual output is configured; not if dates are to be serialized as time stamps).
 TypeResolverBuilder<?> getDefaultTyper(JavaType baseType)
          Method called to locate a type info handler for types that do not have one explicitly declared via annotations (or other configuration).
 VisibilityChecker<?> getDefaultVisibilityChecker()
          Accessor for object used for determining whether specific property elements (method, constructors, fields) can be auto-detected based on their visibility (access modifiers).
 JsonSerialize.Inclusion getSerializationInclusion()
           
 Class<?> getSerializationView()
          Method for checking which serialization view is being used, if any; null if none.
 SubtypeResolver getSubtypeResolver()
          Accessor for object used for finding out all reachable subtypes for supertypes; needed when a logical type name is used instead of class name (or custom scheme).
<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 isEnabled(SerializationConfig.Feature f)
          Method for checking whether given feature is enabled or not
 void set(SerializationConfig.Feature f, boolean state)
          Method for enabling or disabling specified feature.
 void setAnnotationIntrospector(AnnotationIntrospector ai)
           
 void setDateFormat(DateFormat df)
          Method that will set the specific date format to use for serializing Dates (and Calendars); or if null passed, simply disable textual serialization and use timestamp.
 void setIntrospector(ClassIntrospector<? extends BeanDescription> i)
           
 void setMixInAnnotations(Map<Class<?>,Class<?>> sourceMixins)
          Method to use for defining mix-in annotations to use for augmenting annotations that serializable classes have.
 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)
          Method for checking which serialization view is being used, if any; null if none.
 void setSubtypeResolver(SubtypeResolver r)
          Method for overriding subtype resolver used.
 String toString()
           
 
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.


_classIntrospector

protected ClassIntrospector<? extends BeanDescription> _classIntrospector
Introspector used to figure out Bean properties needed for bean serialization and deserialization. Overridable so that it is possible to change low-level details of introspection, like adding new annotation types.


_annotationIntrospector

protected AnnotationIntrospector _annotationIntrospector
Introspector used for accessing annotation value based configuration.


_featureFlags

protected int _featureFlags

_dateFormat

protected DateFormat _dateFormat
Textual date format to use for serialization (if enabled by SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS being set to false). Defaults to a ISO-8601 compliant format used by StdDateFormat.

Note that format object is not to be used as is by caller: since date format objects are not thread-safe, caller has to create a clone first.


_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.


_mixInAnnotations

protected HashMap<ClassKey,Class<?>> _mixInAnnotations
Mapping that defines how to apply mix-in annotations: key is the type to received additional annotations, and value is the type that has annotations to "mix in".

Annotations associated with the value classes will be used to override annotations of the key class, associated with the same field or method. They can be further masked by sub-classes: you can think of it as injecting annotations between the target class and its sub-classes (or interfaces)

Since:
1.2

_mixInAnnotationsShared

protected boolean _mixInAnnotationsShared
Flag used to detect when a copy if mix-in annotations is needed: set when current copy is shared, cleared when a fresh copy is maed

Since:
1.2

_typer

protected final TypeResolverBuilder<?> _typer
Type information handler used for "untyped" values (ones declared to have type Object.class)

Since:
1.5

_visibilityChecker

protected VisibilityChecker<?> _visibilityChecker
Object used for determining whether specific property elements (method, constructors, fields) can be auto-detected based on their visibility (access modifiers). Can be changed to allow different minimum visibility levels for auto-detection. Note that this is the global handler; individual types (classes) can further override active checker used (using JsonAutoDetect annotation)

Since:
1.5

_subtypeResolver

protected SubtypeResolver _subtypeResolver
Registered concrete subtypes that can be used instead of (or in addition to) ones declared using annotations.

Since:
1.6
Constructor Detail

SerializationConfig

public SerializationConfig(ClassIntrospector<? extends BeanDescription> intr,
                           AnnotationIntrospector annIntr,
                           VisibilityChecker<?> vc,
                           SubtypeResolver subtypeResolver)

SerializationConfig

protected SerializationConfig(SerializationConfig src,
                              HashMap<ClassKey,Class<?>> mixins,
                              TypeResolverBuilder<?> typer,
                              VisibilityChecker<?> vc,
                              SubtypeResolver subtypeResolver)
Method Detail

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 interface MapperConfig<SerializationConfig>
Parameters:
cls - Class of which class annotations to use for changing configuration settings

createUnshared

public SerializationConfig createUnshared(TypeResolverBuilder<?> typer,
                                          VisibilityChecker<?> vc,
                                          SubtypeResolver subtypeResolver)
Method that is called to create a non-shared copy of the configuration to be used for a serialization operation. Note that if sub-classing and sub-class has additional instance methods, this method must be overridden to produce proper sub-class instance.

Specified by:
createUnshared in interface MapperConfig<SerializationConfig>

setIntrospector

public void setIntrospector(ClassIntrospector<? extends BeanDescription> i)
Specified by:
setIntrospector in interface MapperConfig<SerializationConfig>

getAnnotationIntrospector

public AnnotationIntrospector getAnnotationIntrospector()
Method for getting AnnotationIntrospector configured to introspect annotation values used for configuration.

Specified by:
getAnnotationIntrospector in interface MapperConfig<SerializationConfig>

setAnnotationIntrospector

public void setAnnotationIntrospector(AnnotationIntrospector ai)
Specified by:
setAnnotationIntrospector in interface MapperConfig<SerializationConfig>

setMixInAnnotations

public void setMixInAnnotations(Map<Class<?>,Class<?>> sourceMixins)
Method to use for defining mix-in annotations to use for augmenting annotations that serializable classes have. Mixing in is done when introspecting class annotations and properties. Map passed contains keys that are target classes (ones to augment with new annotation overrides), and values that are source classes (have annotations to use for augmentation). Annotations from source classes (and their supertypes) will override annotations that target classes (and their super-types) have.

Note: a copy of argument Map is created; the original Map is not modified or retained by this config object.

Specified by:
setMixInAnnotations in interface MapperConfig<SerializationConfig>
Since:
1.2

addMixInAnnotations

public void addMixInAnnotations(Class<?> target,
                                Class<?> mixinSource)
Description copied from interface: MapperConfig
Method to use for adding mix-in annotations to use for augmenting specified class or interface. All annotations from mixinSource are taken to override annotations that target (or its supertypes) has.

Specified by:
addMixInAnnotations in interface MapperConfig<SerializationConfig>
Parameters:
target - Class (or interface) whose annotations to effectively override
mixinSource - Class (or interface) whose annotations are to be "added" to target's annotations, overriding as necessary

findMixInClassFor

public Class<?> findMixInClassFor(Class<?> cls)
Description copied from interface: MapperConfig
Method that will check if there are "mix-in" classes (with mix-in annotations) for given class

Specified by:
findMixInClassFor in interface ClassIntrospector.MixInResolver
Specified by:
findMixInClassFor in interface MapperConfig<SerializationConfig>
Since:
1.2

getDateFormat

public DateFormat getDateFormat()
Description copied from interface: MapperConfig
Method for accessing currently configured (textual) date format that will be used for reading or writing date values (in case of writing, only if textual output is configured; not if dates are to be serialized as time stamps).

Note that typically DateFormat instances are not thread-safe (at least ones provided by JDK): this means that calling code should clone format instance before using it.

This method is usually only called by framework itself, since there are convenience methods available via DeserializationContext and SerializerProvider that take care of cloning and thread-safe reuse.

Specified by:
getDateFormat in interface MapperConfig<SerializationConfig>

setDateFormat

public void setDateFormat(DateFormat df)
Method that will set the specific date format to use for serializing Dates (and Calendars); or if null passed, simply disable textual serialization and use timestamp. In addition to setting format, will also enable/disable feature SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS: enable, if argument is null; disable if non-null.

Specified by:
setDateFormat in interface MapperConfig<SerializationConfig>

getDefaultTyper

public TypeResolverBuilder<?> getDefaultTyper(JavaType baseType)
Description copied from interface: MapperConfig
Method called to locate a type info handler for types that do not have one explicitly declared via annotations (or other configuration). If such default handler is configured, it is returned; otherwise null is returned.

Specified by:
getDefaultTyper in interface MapperConfig<SerializationConfig>

getDefaultVisibilityChecker

public VisibilityChecker<?> getDefaultVisibilityChecker()
Description copied from interface: MapperConfig
Accessor for object used for determining whether specific property elements (method, constructors, fields) can be auto-detected based on their visibility (access modifiers). Can be changed to allow different minimum visibility levels for auto-detection. Note that this is the global handler; individual types (classes) can further override active checker used (using JsonAutoDetect annotation)

Specified by:
getDefaultVisibilityChecker in interface MapperConfig<SerializationConfig>

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


introspect

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


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.


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.


getSubtypeResolver

public SubtypeResolver getSubtypeResolver()
Description copied from interface: MapperConfig
Accessor for object used for finding out all reachable subtypes for supertypes; needed when a logical type name is used instead of class name (or custom scheme).

Specified by:
getSubtypeResolver in interface MapperConfig<SerializationConfig>
Since:
1.6

setSubtypeResolver

public void setSubtypeResolver(SubtypeResolver r)
Description copied from interface: MapperConfig
Method for overriding subtype resolver used.

Specified by:
setSubtypeResolver in interface MapperConfig<SerializationConfig>
Since:
1.6

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)


setSerializationView

public void setSerializationView(Class<?> view)
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