Class SerializationConfig
- All Implemented Interfaces:
ClassIntrospector.MixInResolver
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.
As of version 1.9, the goal is to make this class eventually immutable. Because of this, existing methods that allow changing state of this instance are deprecated in favor of methods that create new instances with different configuration ("fluent factories")
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration that defines togglable features that guide the serialization feature.Nested classes/interfaces inherited from class MapperConfig
MapperConfig.Base, MapperConfig.ConfigFeature -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intNote: moved to base class in 1.9; was stored by sub-class earlierprotected FilterProviderObject used for resolving filter ids to filter instances.protected JsonSerialize.InclusionWhich 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<?> View to use for filtering out properties to serialize.Fields inherited from class MapperConfig
_base, _mixInAnnotations, _mixInAnnotationsShared, _subtypeResolver, DEFAULT_DATE_FORMAT -
Constructor Summary
ConstructorsModifierConstructorDescriptionSerializationConfig(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.protectedprotectedSerializationConfig(SerializationConfig src, int features) protectedSerializationConfig(SerializationConfig src, Class<?> view) protectedSerializationConfig(SerializationConfig src, HashMap<ClassKey, Class<?>> mixins, SubtypeResolver str) Constructor used to make a private copy of specific mix-in definitions.protectedprotectedprotectedSerializationConfig(SerializationConfig src, FilterProvider filters) -
Method Summary
Modifier and TypeMethodDescriptionbooleanAccessor 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.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)voidDeprecated.voidDeprecated.Since 1.9, it is preferable to usewith(SerializationConfig.Feature...)instead; this method is deprecated as it modifies current instance instead of creating a new one (as the goal is to make this class immutable)voidfromAnnotations(Class<?> cls) Deprecated.Since 1.9, it is preferably to explicitly configure instances; this method also modifies existing instance which is against immutable design goals of this class.Method for gettingAnnotationIntrospectorconfigured to introspect annotation values used for configuration.Accessor for object used for determining whether specific property elements (method, constructors, fields) can be auto-detected based on their visibility (access modifiers).Method for getting provider used for locating filters given id (which is usually provided with filter annotations).Class<?> Method for checking which serialization view is being used, if any; null if none.<T extends BeanDescription>
Tintrospect(JavaType type) Method that will introspect full bean properties for the purpose of building a bean serializer<T extends BeanDescription>
TAccessor for getting bean description that only contains class annotations: useful if no getter/setter/creator information is needed.<T extends BeanDescription>
TAccessor 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.booleanMethod for determining whether annotation processing is enabled or not (default settings are typically that it is enabled; must explicitly disable).booleanMethod for checking whether given feature is enabled or notbooleanserializerInstance(Annotated annotated, Class<? extends JsonSerializer<?>> serClass) voidset(SerializationConfig.Feature f, boolean state) Deprecated.Since 1.9, it is preferable to usewithout(SerializationConfig.Feature...)andwith(SerializationConfig.Feature...)instead; this method is deprecated as it modifies current instance instead of creating a new one (as the goal is to make this class immutable)final voidDeprecated.Since 1.8, usewithDateFormat(DateFormat)instead.voidDeprecated.since 1.9 should either usewithSerializationInclusion(JsonSerialize.Inclusion)to construct new instance, or configure throughObjectMappervoidsetSerializationView(Class<?> view) Deprecated.Since 1.8, usewithView(Class)insteadbooleanAccessor for checking whether default settings for property handling indicate that properties should be alphabetically ordered or not.toString()with(SerializationConfig.Feature... features) Fluent factory method that will construct and return a new configuration object instance with specified features enabled.Method for constructing and returning a new instance with differentAnnotationIntrospectorto use (replacing old one).Method for constructing and returning a new instance with additionalAnnotationIntrospectorappended (as the lowest priority one)withClassIntrospector(ClassIntrospector<? extends BeanDescription> ci) Method for constructing and returning a new instance with differentClassIntrospectorto use.In addition to constructing instance with specified date format, will enable or disableFeature.WRITE_DATES_AS_TIMESTAMPS(enable if format set as null; disable if non-null)withFilters(FilterProvider filterProvider) Method for constructing and returning a new instance with differentHandlerInstantiatorto use.Method for constructing and returning a new instance with additionalAnnotationIntrospectorinserted (as the highest priority one)without(SerializationConfig.Feature... features) Fluent factory method that will construct and return a new configuration object instance with specified features disabled.Method for constructing and returning a new instance with differentPropertyNamingStrategyto use.Method for constructing and returning a new instance with differentSubtypeResolverto use.Method for constructing and returning a new instance with differentTypeFactoryto use.Method for constructing and returning a new instance with differentTypeResolverBuilderto use.withVisibility(JsonMethod forMethod, JsonAutoDetect.Visibility visibility) Method for constructing and returning a new instance with different minimal visibility level for specified property typeMethod for constructing and returning a new instance with differentVisibilityCheckerto use.Methods inherited from class MapperConfig
addMixInAnnotations, appendAnnotationIntrospector, constructSpecializedType, constructType, constructType, findMixInClassFor, getClassIntrospector, getDateFormat, getDefaultTyper, getHandlerInstantiator, getPropertyNamingStrategy, getSubtypeResolver, getTypeFactory, insertAnnotationIntrospector, introspectClassAnnotations, introspectDirectClassAnnotations, mixInCount, setAnnotationIntrospector, setMixInAnnotations, typeIdResolverInstance, typeResolverBuilderInstance
-
Field Details
-
_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_PROPERTIESto choose betweenJsonSerialize.Inclusion.ALWAYSandJsonSerialize.Inclusion.NON_NULL. -
_serializationView
View to use for filtering out properties to serialize. Null if none (will also be assigned null ifObject.classis defined), meaning that all properties are to be included. -
_filterProvider
Object used for resolving filter ids to filter instances. Non-null if explicitly defined; null by default.- Since:
- 1.7
-
_featureFlags
protected int _featureFlagsNote: moved to base class in 1.9; was stored by sub-class earlier
-
-
Constructor Details
-
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
- 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
- Since:
- 1.8
-
SerializationConfig
- Since:
- 1.8
-
SerializationConfig
- Since:
- 1.8
-
SerializationConfig
- Since:
- 1.9
-
SerializationConfig
- Since:
- 1.9
-
-
Method Details
-
withClassIntrospector
Description copied from class:MapperConfigMethod for constructing and returning a new instance with differentClassIntrospectorto use.NOTE: make sure to register new instance with
ObjectMapperif directly calling this method.- Specified by:
withClassIntrospectorin classMapperConfig<SerializationConfig>
-
withAnnotationIntrospector
Description copied from class:MapperConfigMethod for constructing and returning a new instance with differentAnnotationIntrospectorto use (replacing old one).NOTE: make sure to register new instance with
ObjectMapperif directly calling this method.- Specified by:
withAnnotationIntrospectorin classMapperConfig<SerializationConfig>
-
withInsertedAnnotationIntrospector
Description copied from class:MapperConfigMethod for constructing and returning a new instance with additionalAnnotationIntrospectorinserted (as the highest priority one)- Specified by:
withInsertedAnnotationIntrospectorin classMapperConfig<SerializationConfig>
-
withAppendedAnnotationIntrospector
Description copied from class:MapperConfigMethod for constructing and returning a new instance with additionalAnnotationIntrospectorappended (as the lowest priority one)- Specified by:
withAppendedAnnotationIntrospectorin classMapperConfig<SerializationConfig>
-
withVisibilityChecker
Description copied from class:MapperConfigMethod for constructing and returning a new instance with differentVisibilityCheckerto use.NOTE: make sure to register new instance with
ObjectMapperif directly calling this method.- Specified by:
withVisibilityCheckerin classMapperConfig<SerializationConfig>
-
withVisibility
public SerializationConfig withVisibility(JsonMethod forMethod, JsonAutoDetect.Visibility visibility) Description copied from class:MapperConfigMethod for constructing and returning a new instance with different minimal visibility level for specified property typeNOTE: make sure to register new instance with
ObjectMapperif directly calling this method.- Specified by:
withVisibilityin classMapperConfig<SerializationConfig>
-
withTypeResolverBuilder
Description copied from class:MapperConfigMethod for constructing and returning a new instance with differentTypeResolverBuilderto use.NOTE: make sure to register new instance with
ObjectMapperif directly calling this method.- Specified by:
withTypeResolverBuilderin classMapperConfig<SerializationConfig>
-
withSubtypeResolver
Description copied from class:MapperConfigMethod for constructing and returning a new instance with differentSubtypeResolverto use.NOTE: make sure to register new instance with
ObjectMapperif directly calling this method.- Specified by:
withSubtypeResolverin classMapperConfig<SerializationConfig>
-
withPropertyNamingStrategy
Description copied from class:MapperConfigMethod for constructing and returning a new instance with differentPropertyNamingStrategyto use.NOTE: make sure to register new instance with
ObjectMapperif directly calling this method.- Specified by:
withPropertyNamingStrategyin classMapperConfig<SerializationConfig>
-
withTypeFactory
Description copied from class:MapperConfigMethod for constructing and returning a new instance with differentTypeFactoryto use.NOTE: make sure to register new instance with
ObjectMapperif directly calling this method.- Specified by:
withTypeFactoryin classMapperConfig<SerializationConfig>
-
withDateFormat
In addition to constructing instance with specified date format, will enable or disableFeature.WRITE_DATES_AS_TIMESTAMPS(enable if format set as null; disable if non-null)- Specified by:
withDateFormatin classMapperConfig<SerializationConfig>
-
withHandlerInstantiator
Description copied from class:MapperConfigMethod for constructing and returning a new instance with differentHandlerInstantiatorto use.NOTE: make sure to register new instance with
ObjectMapperif directly calling this method.- Specified by:
withHandlerInstantiatorin classMapperConfig<SerializationConfig>
-
withFilters
- Since:
- 1.7
-
withView
- Since:
- 1.8
-
withSerializationInclusion
- Since:
- 1.9
-
with
Fluent factory method that will construct and return a new configuration object instance with specified features enabled.- Since:
- 1.9
-
without
Fluent factory method that will construct and return a new configuration object instance with specified features disabled.- Since:
- 1.9
-
fromAnnotations
Deprecated.Since 1.9, it is preferably to explicitly configure instances; this method also modifies existing instance which is against immutable design goals of this class.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:
fromAnnotationsin classMapperConfig<SerializationConfig>- Parameters:
cls- Class of which class annotations to use for changing configuration settings
-
getAnnotationIntrospector
Description copied from class:MapperConfigMethod for gettingAnnotationIntrospectorconfigured to introspect annotation values used for configuration.Non-final since it is actually overridden by sub-classes (for now?)
- Overrides:
getAnnotationIntrospectorin classMapperConfig<SerializationConfig>
-
introspectClassAnnotations
Accessor for getting bean description that only contains class annotations: useful if no getter/setter/creator information is needed.Note: part of
MapperConfigsince 1.7- Specified by:
introspectClassAnnotationsin classMapperConfig<SerializationConfig>
-
introspectDirectClassAnnotations
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
MapperConfigsince 1.7- Specified by:
introspectDirectClassAnnotationsin classMapperConfig<SerializationConfig>
-
isAnnotationProcessingEnabled
public boolean isAnnotationProcessingEnabled()Description copied from class:MapperConfigMethod for determining whether annotation processing is enabled or not (default settings are typically that it is enabled; must explicitly disable).- Specified by:
isAnnotationProcessingEnabledin classMapperConfig<SerializationConfig>- Returns:
- True if annotation processing is enabled; false if not
-
canOverrideAccessModifiers
public boolean canOverrideAccessModifiers()Description copied from class:MapperConfigAccessor 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:
canOverrideAccessModifiersin classMapperConfig<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.
-
shouldSortPropertiesAlphabetically
public boolean shouldSortPropertiesAlphabetically()Description copied from class:MapperConfigAccessor for checking whether default settings for property handling indicate that properties should be alphabetically ordered or not.- Specified by:
shouldSortPropertiesAlphabeticallyin classMapperConfig<SerializationConfig>
-
getDefaultVisibilityChecker
Description copied from class:MapperConfigAccessor 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 (usingJsonAutoDetectannotation)- Overrides:
getDefaultVisibilityCheckerin classMapperConfig<SerializationConfig>
-
isEnabled
- Since:
- 1.0 However, note that version 1.9.0 and 1.9.1 accidentally missed this overloaded variant
-
enable
Deprecated.Since 1.9, it is preferable to usewith(SerializationConfig.Feature...)instead; this method is deprecated as it modifies current instance instead of creating a new one (as the goal is to make this class immutable)Method for enabling specified feature. -
disable
Deprecated.Since 1.9, it is preferable to usewithout(SerializationConfig.Feature...)instead; this method is deprecated as it modifies current instance instead of creating a new one (as the goal is to make this class immutable)Method for disabling specified feature. -
set
Deprecated.Since 1.9, it is preferable to usewithout(SerializationConfig.Feature...)andwith(SerializationConfig.Feature...)instead; this method is deprecated as it modifies current instance instead of creating a new one (as the goal is to make this class immutable)Method for enabling or disabling specified feature. -
getSerializationView
Method for checking which serialization view is being used, if any; null if none.- Since:
- 1.4
-
getSerializationInclusion
-
setSerializationInclusion
Deprecated.since 1.9 should either usewithSerializationInclusion(JsonSerialize.Inclusion)to construct new instance, or configure throughObjectMapperMethod 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
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 forObjectWriter(or if serialization directly called fromObjectMapper)- Since:
- 1.7
-
introspect
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) -
setDateFormat
Deprecated.Since 1.8, usewithDateFormat(DateFormat)instead.One thing to note is that this will setSerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPSto false (if null format set), or true (if non-null format)- Overrides:
setDateFormatin classMapperConfig<SerializationConfig>- Parameters:
df- Date format to use, if not null; if null, the default format will be used
-
setSerializationView
Deprecated.Since 1.8, usewithView(Class)insteadMethod for checking which serialization view is being used, if any; null if none.- Since:
- 1.4
-
toString
-
isEnabled
Description copied from class:MapperConfigMethod for checking whether given feature is enabled or not- Specified by:
isEnabledin classMapperConfig<T extends org.codehaus.jackson.map.MapperConfig.Impl<CFG,T>>
-
without(SerializationConfig.Feature...)instead; this method is deprecated as it modifies current instance instead of creating a new one (as the goal is to make this class immutable)