org.codehaus.jackson.map
Class SerializationConfig

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

public class SerializationConfig
extends Object
implements MapperConfig

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 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)
           
protected SerializationConfig(SerializationConfig src, HashMap<ClassKey,Class<?>> mixins)
           
 
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()
          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()
           
 JsonSerialize.Inclusion getSerializationInclusion()
           
 Class<?> getSerializationView()
          Method for checking which serialization view is being used, if any; null if none.
<T extends BeanDescription>
T
introspect(Class<?> cls)
          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.
 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 textual serialization 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.
 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
Constructor Detail

SerializationConfig

public SerializationConfig(ClassIntrospector<? extends BeanDescription> intr,
                           AnnotationIntrospector annIntr)

SerializationConfig

protected SerializationConfig(SerializationConfig src,
                              HashMap<ClassKey,Class<?>> mixins)
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
Parameters:
cls - Class of which class annotations to use for changing configuration settings

createUnshared

public SerializationConfig createUnshared()
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

setIntrospector

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

getAnnotationIntrospector

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

Specified by:
getAnnotationIntrospector in interface MapperConfig

setAnnotationIntrospector

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

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
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
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
Since:
1.2

isEnabled

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


getDateFormat

public DateFormat getDateFormat()

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()

introspect

public <T extends BeanDescription> T introspect(Class<?> cls)
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.


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.


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)


setDateFormat

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


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