Class MapperConfig<T extends MapperConfig<T>>
- java.lang.Object
-
- org.codehaus.jackson.map.MapperConfig<T>
-
- All Implemented Interfaces:
ClassIntrospector.MixInResolver
- Direct Known Subclasses:
DeserializationConfig,SerializationConfig
public abstract class MapperConfig<T extends MapperConfig<T>> extends Object implements ClassIntrospector.MixInResolver
Interface that defines functionality accessible through both serialization and deserialization configuration objects; accessors to mode-independent configuration settings and such.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"). One major remaining issue is that of handling mix-in annotations, which still represent a bit of mutable state; may need to implement a functional-style immutable map for storing those.
- Since:
- 1.2 -- major change in 1.8, changed from interface to abstract class
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMapperConfig.BaseImmutable container class used to store simple configuration settings.static interfaceMapperConfig.ConfigFeatureInterface that actual Feature enumerations used byMapperConfigimplementations must implement.
-
Field Summary
Fields Modifier and Type Field Description protected MapperConfig.Base_baseImmutable container object for simple configuration settings.protected HashMap<ClassKey,Class<?>>_mixInAnnotationsMapping 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_mixInAnnotationsSharedFlag used to detect when a copy if mix-in annotations is needed: set when current copy is shared, cleared when a fresh copy is madeprotected SubtypeResolver_subtypeResolverRegistered concrete subtypes that can be used instead of (or in addition to) ones declared using annotations.protected static DateFormatDEFAULT_DATE_FORMATThis is the defaultDateFormatused unless overridden by custom implementation.
-
Constructor Summary
Constructors Modifier Constructor Description protectedMapperConfig(ClassIntrospector<? extends BeanDescription> ci, AnnotationIntrospector ai, VisibilityChecker<?> vc, SubtypeResolver str, PropertyNamingStrategy pns, TypeFactory tf, HandlerInstantiator hi)protectedMapperConfig(MapperConfig<T> src)Simple copy constructorprotectedMapperConfig(MapperConfig<T> src, MapperConfig.Base base, SubtypeResolver str)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddMixInAnnotations(Class<?> target, Class<?> mixinSource)Method to use for adding mix-in annotations to use for augmenting specified class or interface.voidappendAnnotationIntrospector(AnnotationIntrospector introspector)Deprecated.Since 1.9 usewithAppendedAnnotationIntrospector(AnnotationIntrospector)instead; this method is deprecated as it changes state, preventing immutability of instancesabstract booleancanOverrideAccessModifiers()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.JavaTypeconstructSpecializedType(JavaType baseType, Class<?> subclass)JavaTypeconstructType(Class<?> cls)Helper method that will constructJavaTypefor given raw class.JavaTypeconstructType(TypeReference<?> valueTypeRef)Helper method that will constructJavaTypefor given type reference This is a simple short-cut for:abstract TcreateUnshared(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)Class<?>findMixInClassFor(Class<?> cls)Method that will check if there are "mix-in" classes (with mix-in annotations) for given classabstract 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.AnnotationIntrospectorgetAnnotationIntrospector()Method for gettingAnnotationIntrospectorconfigured to introspect annotation values used for configuration.ClassIntrospector<? extends BeanDescription>getClassIntrospector()DateFormatgetDateFormat()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).HandlerInstantiatorgetHandlerInstantiator()PropertyNamingStrategygetPropertyNamingStrategy()SubtypeResolvergetSubtypeResolver()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).TypeFactorygetTypeFactory()voidinsertAnnotationIntrospector(AnnotationIntrospector introspector)Deprecated.Since 1.9 usewithInsertedAnnotationIntrospector(AnnotationIntrospector)instead; this method is deprecated as it changes state, preventing immutability of instances<DESC extends BeanDescription>
DESCintrospectClassAnnotations(Class<?> cls)Accessor for getting bean description that only contains class annotations: useful if no getter/setter/creator information is needed.abstract <DESC extends BeanDescription>
DESCintrospectClassAnnotations(JavaType type)Accessor for getting bean description that only contains class annotations: useful if no getter/setter/creator information is needed.<DESC extends BeanDescription>
DESCintrospectDirectClassAnnotations(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.abstract <DESC extends BeanDescription>
DESCintrospectDirectClassAnnotations(JavaType type)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.abstract booleanisAnnotationProcessingEnabled()Method for determining whether annotation processing is enabled or not (default settings are typically that it is enabled; must explicitly disable).abstract booleanisEnabled(MapperConfig.ConfigFeature f)Method for checking whether given feature is enabled or notintmixInCount()voidsetAnnotationIntrospector(AnnotationIntrospector ai)Deprecated.Since 1.8, use eitherwithAnnotationIntrospector(AnnotationIntrospector)or Module API insteadvoidsetDateFormat(DateFormat df)Deprecated.As of version 1.8, it is preferable to call method inObjectMapperinstead; or construct new instance withwithDateFormat(DateFormat)voidsetMixInAnnotations(Map<Class<?>,Class<?>> sourceMixins)Method to use for defining mix-in annotations to use for augmenting annotations that processable (serializable / deserializable) classes have.abstract booleanshouldSortPropertiesAlphabetically()Accessor for checking whether default settings for property handling indicate that properties should be alphabetically ordered or not.TypeIdResolvertypeIdResolverInstance(Annotated annotated, Class<? extends TypeIdResolver> resolverClass)Method that can be called to obtain an instance ofTypeIdResolverof specified type.TypeResolverBuilder<?>typeResolverBuilderInstance(Annotated annotated, Class<? extends TypeResolverBuilder<?>> builderClass)Method that can be called to obtain an instance ofTypeIdResolverof specified type.abstract TwithAnnotationIntrospector(AnnotationIntrospector ai)Method for constructing and returning a new instance with differentAnnotationIntrospectorto use (replacing old one).abstract TwithAppendedAnnotationIntrospector(AnnotationIntrospector introspector)Method for constructing and returning a new instance with additionalAnnotationIntrospectorappended (as the lowest priority one)abstract TwithClassIntrospector(ClassIntrospector<? extends BeanDescription> ci)Method for constructing and returning a new instance with differentClassIntrospectorto use.abstract TwithDateFormat(DateFormat df)Method for constructing and returning a new instance with differentDateFormatto use.abstract TwithHandlerInstantiator(HandlerInstantiator hi)Method for constructing and returning a new instance with differentHandlerInstantiatorto use.abstract TwithInsertedAnnotationIntrospector(AnnotationIntrospector introspector)Method for constructing and returning a new instance with additionalAnnotationIntrospectorinserted (as the highest priority one)abstract TwithPropertyNamingStrategy(PropertyNamingStrategy strategy)Method for constructing and returning a new instance with differentPropertyNamingStrategyto use.abstract TwithSubtypeResolver(SubtypeResolver str)Method for constructing and returning a new instance with differentSubtypeResolverto use.abstract TwithTypeFactory(TypeFactory typeFactory)Method for constructing and returning a new instance with differentTypeFactoryto use.abstract TwithTypeResolverBuilder(TypeResolverBuilder<?> trb)Method for constructing and returning a new instance with differentTypeResolverBuilderto use.abstract TwithVisibility(JsonMethod forMethod, JsonAutoDetect.Visibility visibility)Method for constructing and returning a new instance with different minimal visibility level for specified property typeabstract TwithVisibilityChecker(VisibilityChecker<?> vc)Method for constructing and returning a new instance with differentVisibilityCheckerto use.
-
-
-
Field Detail
-
DEFAULT_DATE_FORMAT
protected static final DateFormat DEFAULT_DATE_FORMAT
This is the defaultDateFormatused unless overridden by custom implementation.
-
_base
protected MapperConfig.Base _base
Immutable container object for simple configuration settings.Note: ideally this would be final, but until we can eliminate mutators, must keep it mutable.
-
_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 made- Since:
- 1.2
-
_subtypeResolver
protected SubtypeResolver _subtypeResolver
Registered concrete subtypes that can be used instead of (or in addition to) ones declared using annotations. Unlike most other settings, it is not configured as early as it is set, but rather only when a non-shared instance is constructed byObjectMapper(or -Reader or -Writer)Note: this is the only property left as non-final, to allow lazy construction of the instance as necessary.
- Since:
- 1.6
-
-
Constructor Detail
-
MapperConfig
protected MapperConfig(ClassIntrospector<? extends BeanDescription> ci, AnnotationIntrospector ai, VisibilityChecker<?> vc, SubtypeResolver str, PropertyNamingStrategy pns, TypeFactory tf, HandlerInstantiator hi)
-
MapperConfig
protected MapperConfig(MapperConfig<T> src)
Simple copy constructor- Since:
- 1.8
-
MapperConfig
protected MapperConfig(MapperConfig<T> src, MapperConfig.Base base, SubtypeResolver str)
- Since:
- 1.8
-
-
Method Detail
-
fromAnnotations
@Deprecated public abstract void fromAnnotations(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 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.
-
createUnshared
public abstract T 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)- Since:
- 1.8
-
withClassIntrospector
public abstract T withClassIntrospector(ClassIntrospector<? extends BeanDescription> ci)
Method for constructing and returning a new instance with differentClassIntrospectorto use.NOTE: make sure to register new instance with
ObjectMapperif directly calling this method.- Since:
- 1.8
-
withAnnotationIntrospector
public abstract T withAnnotationIntrospector(AnnotationIntrospector ai)
Method 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.- Since:
- 1.8
-
withVisibilityChecker
public abstract T withVisibilityChecker(VisibilityChecker<?> vc)
Method for constructing and returning a new instance with differentVisibilityCheckerto use.NOTE: make sure to register new instance with
ObjectMapperif directly calling this method.- Since:
- 1.8
-
withVisibility
public abstract T withVisibility(JsonMethod forMethod, JsonAutoDetect.Visibility visibility)
Method 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.- Since:
- 1.9
-
withTypeResolverBuilder
public abstract T withTypeResolverBuilder(TypeResolverBuilder<?> trb)
Method for constructing and returning a new instance with differentTypeResolverBuilderto use.NOTE: make sure to register new instance with
ObjectMapperif directly calling this method.- Since:
- 1.8
-
withSubtypeResolver
public abstract T withSubtypeResolver(SubtypeResolver str)
Method for constructing and returning a new instance with differentSubtypeResolverto use.NOTE: make sure to register new instance with
ObjectMapperif directly calling this method.- Since:
- 1.8
-
withPropertyNamingStrategy
public abstract T withPropertyNamingStrategy(PropertyNamingStrategy strategy)
Method for constructing and returning a new instance with differentPropertyNamingStrategyto use.NOTE: make sure to register new instance with
ObjectMapperif directly calling this method.- Since:
- 1.8
-
withTypeFactory
public abstract T withTypeFactory(TypeFactory typeFactory)
Method for constructing and returning a new instance with differentTypeFactoryto use.NOTE: make sure to register new instance with
ObjectMapperif directly calling this method.- Since:
- 1.8
-
withDateFormat
public abstract T withDateFormat(DateFormat df)
Method for constructing and returning a new instance with differentDateFormatto use.NOTE: make sure to register new instance with
ObjectMapperif directly calling this method.- Since:
- 1.8
-
withHandlerInstantiator
public abstract T withHandlerInstantiator(HandlerInstantiator hi)
Method for constructing and returning a new instance with differentHandlerInstantiatorto use.NOTE: make sure to register new instance with
ObjectMapperif directly calling this method.- Since:
- 1.8
-
withInsertedAnnotationIntrospector
public abstract T withInsertedAnnotationIntrospector(AnnotationIntrospector introspector)
Method for constructing and returning a new instance with additionalAnnotationIntrospectorinserted (as the highest priority one)- Since:
- 1.9
-
withAppendedAnnotationIntrospector
public abstract T withAppendedAnnotationIntrospector(AnnotationIntrospector introspector)
Method for constructing and returning a new instance with additionalAnnotationIntrospectorappended (as the lowest priority one)- Since:
- 1.9
-
isEnabled
public abstract boolean isEnabled(MapperConfig.ConfigFeature f)
Method for checking whether given feature is enabled or not
-
isAnnotationProcessingEnabled
public abstract boolean isAnnotationProcessingEnabled()
Method for determining whether annotation processing is enabled or not (default settings are typically that it is enabled; must explicitly disable).- Returns:
- True if annotation processing is enabled; false if not
- Since:
- 1.8
-
canOverrideAccessModifiers
public abstract 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. By default this is enabled, but on some platforms it needs to be prevented since if this would violate security constraints and cause failures.- 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.
- Since:
- 1.8
-
shouldSortPropertiesAlphabetically
public abstract boolean shouldSortPropertiesAlphabetically()
Accessor for checking whether default settings for property handling indicate that properties should be alphabetically ordered or not.- Since:
- 1.9
-
getClassIntrospector
public ClassIntrospector<? extends BeanDescription> getClassIntrospector()
-
getAnnotationIntrospector
public AnnotationIntrospector getAnnotationIntrospector()
Method for gettingAnnotationIntrospectorconfigured to introspect annotation values used for configuration.Non-final since it is actually overridden by sub-classes (for now?)
-
insertAnnotationIntrospector
@Deprecated public final void insertAnnotationIntrospector(AnnotationIntrospector introspector)
Deprecated.Since 1.9 usewithInsertedAnnotationIntrospector(AnnotationIntrospector)instead; this method is deprecated as it changes state, preventing immutability of instancesMethod for registering specifiedAnnotationIntrospectoras the highest priority introspector (will be chained with existing introspector(s) which will be used as fallbacks for cases this introspector does not handle)- Parameters:
introspector- Annotation introspector to register.- Since:
- 1.7
-
appendAnnotationIntrospector
@Deprecated public final void appendAnnotationIntrospector(AnnotationIntrospector introspector)
Deprecated.Since 1.9 usewithAppendedAnnotationIntrospector(AnnotationIntrospector)instead; this method is deprecated as it changes state, preventing immutability of instancesMethod for registering specifiedAnnotationIntrospectoras the lowest priority introspector, chained with existing introspector(s) and called as fallback for cases not otherwise handled.- Parameters:
introspector- Annotation introspector to register.- Since:
- 1.7
-
getDefaultVisibilityChecker
public 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). 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)- Since:
- 1.5
-
getPropertyNamingStrategy
public final PropertyNamingStrategy getPropertyNamingStrategy()
- Since:
- 1.8
-
getHandlerInstantiator
public final HandlerInstantiator getHandlerInstantiator()
- Since:
- 1.8
-
setMixInAnnotations
public final void setMixInAnnotations(Map<Class<?>,Class<?>> sourceMixins)
Method to use for defining mix-in annotations to use for augmenting annotations that processable (serializable / deserializable) 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.- Since:
- 1.2
-
addMixInAnnotations
public final void addMixInAnnotations(Class<?> target, Class<?> mixinSource)
Method to use for adding mix-in annotations to use for augmenting specified class or interface. All annotations frommixinSourceare taken to override annotations thattarget(or its supertypes) has.- Parameters:
target- Class (or interface) whose annotations to effectively overridemixinSource- Class (or interface) whose annotations are to be "added" to target's annotations, overriding as necessary- Since:
- 1.2
-
findMixInClassFor
public final Class<?> findMixInClassFor(Class<?> cls)
Method that will check if there are "mix-in" classes (with mix-in annotations) for given class- Specified by:
findMixInClassForin interfaceClassIntrospector.MixInResolver- Since:
- 1.2
-
mixInCount
public final int mixInCount()
- Since:
- 1.8.1
-
getDefaultTyper
public final 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). If such default handler is configured, it is returned; otherwise null is returned.- Since:
- 1.5
-
getSubtypeResolver
public final 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).- Since:
- 1.6
-
getTypeFactory
public final TypeFactory getTypeFactory()
- Since:
- 1.8
-
constructType
public final JavaType constructType(Class<?> cls)
Helper method that will constructJavaTypefor given raw class. This is a simple short-cut for:getTypeFactory().constructType(cls);- Since:
- 1.8
-
constructType
public final JavaType constructType(TypeReference<?> valueTypeRef)
Helper method that will constructJavaTypefor given type reference This is a simple short-cut for:getTypeFactory().constructType(valueTypeRef);- Since:
- 1.9
-
constructSpecializedType
public JavaType constructSpecializedType(JavaType baseType, Class<?> subclass)
- Since:
- 1.9.1
-
getDateFormat
public final 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).Note that typically
DateFormatinstances 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
DeserializationContextandSerializerProviderthat take care of cloning and thread-safe reuse.
-
introspectClassAnnotations
public <DESC extends BeanDescription> DESC introspectClassAnnotations(Class<?> cls)
Accessor for getting bean description that only contains class annotations: useful if no getter/setter/creator information is needed.- Since:
- 1.7
-
introspectClassAnnotations
public abstract <DESC extends BeanDescription> DESC introspectClassAnnotations(JavaType type)
Accessor for getting bean description that only contains class annotations: useful if no getter/setter/creator information is needed.- Since:
- 1.9
-
introspectDirectClassAnnotations
public <DESC extends BeanDescription> DESC 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.- Since:
- 1.7
-
introspectDirectClassAnnotations
public abstract <DESC extends BeanDescription> DESC introspectDirectClassAnnotations(JavaType type)
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.
-
typeResolverBuilderInstance
public TypeResolverBuilder<?> typeResolverBuilderInstance(Annotated annotated, Class<? extends TypeResolverBuilder<?>> builderClass)
Method that can be called to obtain an instance ofTypeIdResolverof specified type.- Since:
- 1.8
-
typeIdResolverInstance
public TypeIdResolver typeIdResolverInstance(Annotated annotated, Class<? extends TypeIdResolver> resolverClass)
Method that can be called to obtain an instance ofTypeIdResolverof specified type.- Since:
- 1.8
-
setAnnotationIntrospector
@Deprecated public final void setAnnotationIntrospector(AnnotationIntrospector ai)
Deprecated.Since 1.8, use eitherwithAnnotationIntrospector(AnnotationIntrospector)or Module API insteadMethod for replacing existing annotation introspector(s) with specified introspector. Since this method modifies state of configuration object directly, its use is not recommended.
-
setDateFormat
@Deprecated public void setDateFormat(DateFormat df)
Deprecated.As of version 1.8, it is preferable to call method inObjectMapperinstead; or construct new instance withwithDateFormat(DateFormat)Method that will define specific date format to use for reading/writing Date and Calendar values. If null is passed, will useStdDateFormat. Instance is used as is, without creating a clone. Format object in use can be accessed usinggetDateFormat().- Parameters:
df- Date format to use, if not null; if null, the default format will be used
-
-