Class MapperBuilder<M extends ObjectMapper,B extends MapperBuilder<M,B>>
- Direct Known Subclasses:
JsonMapper.Builder
ObjectMapper
s. Same can not be done with 2.10 for backwards-compatibility
reasons; but we can offer sort of "fake" builder, which simply encapsulates
configuration calls. The main (and only) point is to allow gradual upgrade.- Since:
- 2.10
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected final B
_this()
Method for configuringAccessorNamingStrategy
to use for auto-detecting accessor ("getter") and mutator ("setter") methods based on naming of methods.activateDefaultTyping
(PolymorphicTypeValidator subtypeValidator) Convenience method that is equivalent to callingactivateDefaultTyping
(PolymorphicTypeValidator subtypeValidator, ObjectMapper.DefaultTyping dti) Convenience method that is equivalent to callingactivateDefaultTyping
(PolymorphicTypeValidator subtypeValidator, ObjectMapper.DefaultTyping applicability, JsonTypeInfo.As includeAs) Method for enabling automatic inclusion of type information, needed for proper deserialization of polymorphic types (unless types have been annotated withJsonTypeInfo
).activateDefaultTypingAsProperty
(PolymorphicTypeValidator subtypeValidator, ObjectMapper.DefaultTyping applicability, String propertyName) Method for enabling automatic inclusion of type information -- needed for proper deserialization of polymorphic types (unless types have been annotated withJsonTypeInfo
) -- using "As.PROPERTY" inclusion mechanism and specified property name to use for inclusion (default being "@class" since default type information always uses class name as type identifier)Method used for adding aDeserializationProblemHandler
for this builder, at the head of the list (meaning it has priority over handler registered earlier).Method to use for defining mix-in annotations to use for augmenting annotations that classes have, for purpose of configuration serialization and/or deserialization processing.addModules
(Module... modules) addModules
(Iterable<? extends Module> modules) Method for replacingAnnotationIntrospector
used by the mapper instance to be built.build()
Method to call to create actual mapper instance.Method that may be used to remove allDeserializationProblemHandler
s added to this builder (if any).configure
(JsonGenerator.Feature feature, boolean state) configure
(JsonParser.Feature feature, boolean state) configure
(StreamReadFeature feature, boolean state) configure
(StreamWriteFeature feature, boolean state) configure
(DeserializationFeature feature, boolean state) configure
(MapperFeature feature, boolean state) configure
(SerializationFeature feature, boolean state) Method for specifyingConstructorDetector
to use for determining some aspects of creator auto-detection (specifically auto-detection of constructor, and in particular behavior with single-argument constructors).Method for disabling automatic inclusion of type information; if so, only explicitly annotated types (ones withJsonTypeInfo
) will have additional embedded type information.Method for replacing defaultContextAttributes
that the mapper uses: usually one initialized with a set of default shared attributes, but potentially also with a custom implementation.Method that will configure defaultBase64Variant
thatbyte[]
serializers and deserializers will use.Method for configuring the defaultDateFormat
to use when serializing time values as Strings, and deserializing from JSON Strings.Method for setting default Setter configuration, regarding things like merging, null-handling; used for properties for which there are no per-type or per-property overrides (via annotations or config overrides).defaultLocale
(Locale locale) Method for overriding default locale to use for formatting.Method for setting default Setter configuration, regarding things like merging, null-handling; used for properties for which there are no per-type or per-property overrides (via annotations or config overrides).Method for configured default property inclusion to use for serialization.Method for overriding default TimeZone to use for formatting.disable
(JsonGenerator.Feature... features) disable
(JsonParser.Feature... features) disable
(StreamReadFeature... features) disable
(StreamWriteFeature... features) disable
(DeserializationFeature... features) disable
(MapperFeature... features) disable
(SerializationFeature... features) enable
(JsonGenerator.Feature... features) enable
(JsonParser.Feature... features) enable
(StreamReadFeature... features) enable
(StreamWriteFeature... features) enable
(DeserializationFeature... features) enable
(MapperFeature... features) enable
(SerializationFeature... features) filterProvider
(FilterProvider prov) Method for configuring this mapper to use specifiedFilterProvider
for mapping Filter Ids to actual filter instances.Convenience method that is functionally equivalent to:addModules(builder.findModules());
Method for locating available methods, using JDKServiceLoader
facility, along with module-provided SPI.findModules
(ClassLoader classLoader) Method for locating available methods, using JDKServiceLoader
facility, along with module-provided SPI.Method for configuringHandlerInstantiator
to use for creating instances of handlers (such as serializers, deserializers, type and type id resolvers), given a class.boolean
boolean
boolean
boolean
boolean
Method for assigningPolymorphicTypeValidator
to use for validating subtypes when using Class name - based polymorphic deserialization using annotations (validator used with "Default Typing" is specified by passing inactivateDefaultTyping(PolymorphicTypeValidator)
instead).Method for configuringPropertyNamingStrategy
to use for adapting POJO property names (internal) into content property names (external)registerSubtypes
(NamedType... subtypes) registerSubtypes
(Class<?>... subtypes) registerSubtypes
(Collection<Class<?>> subtypes) removeMixIn
(Class<?> target) Method that allows making sure that specifiedtarget
class does not have associated mix-in annotations: basically can be used to undo an earlier call toaddMixIn(java.lang.Class<?>, java.lang.Class<?>)
.Method for configured default property inclusion to use for serialization.setDefaultTyping
(TypeResolverBuilder<?> typer) Method for enabling automatic inclusion of type information, using specified handler object for determining which types this affects, as well as details of how information is embedded.visibility
(PropertyAccessor forMethod, JsonAutoDetect.Visibility visibility) visibility
(VisibilityChecker<?> vc) withCoercionConfig
(LogicalType forType, Consumer<MutableCoercionConfig> handler) Method for changing coercion config for specific logical types, through callback to specific handler.withCoercionConfig
(Class<?> forType, Consumer<MutableCoercionConfig> handler) Method for changing coercion config for specific physical type, through callback to specific handler.Method for changing target-type-independent coercion configuration defaults.withConfigOverride
(Class<?> forType, Consumer<MutableConfigOverride> handler) Method for changing config overrides for specific type, through callback to specific handler.
-
Field Details
-
_mapper
-
-
Constructor Details
-
MapperBuilder
-
-
Method Details
-
build
Method to call to create actual mapper instance.Implementation detail: in 2.10 (but not 3.x) underlying mapper is eagerly constructed when builder is constructed, and method simply returns that instance.
-
isEnabled
-
isEnabled
-
isEnabled
-
isEnabled
-
isEnabled
-
streamFactory
-
enable
-
disable
-
configure
-
enable
-
disable
-
configure
-
enable
-
disable
-
configure
-
enable
-
disable
-
configure
-
enable
-
disable
-
configure
-
enable
-
disable
-
configure
-
enable
-
disable
-
configure
-
withConfigOverride
Method for changing config overrides for specific type, through callback to specific handler.- Parameters:
forType
- Type to change config overrides forhandler
- Function to call withMutableConfigOverride
- Since:
- 2.13
-
withCoercionConfig
Method for changing coercion config for specific logical types, through callback to specific handler.- Since:
- 2.13
-
withCoercionConfig
Method for changing coercion config for specific physical type, through callback to specific handler.- Since:
- 2.13
-
withCoercionConfigDefaults
Method for changing target-type-independent coercion configuration defaults.- Since:
- 2.13
-
addModule
-
addModules
-
addModules
-
findModules
Method for locating available methods, using JDKServiceLoader
facility, along with module-provided SPI.Note that method does not do any caching, so calls should be considered potentially expensive.
-
findModules
Method for locating available methods, using JDKServiceLoader
facility, along with module-provided SPI.Note that method does not do any caching, so calls should be considered potentially expensive.
-
findAndAddModules
Convenience method that is functionally equivalent to:addModules(builder.findModules());
As with
findModules()
, no caching is done for modules, so care needs to be taken to either create and share a single mapper instance; or to cache introspected set of modules. -
annotationIntrospector
Method for replacingAnnotationIntrospector
used by the mapper instance to be built. Note that doing this will replace the current introspector, which may lead to unavailability of core Jackson annotations. If you want to combine handling of multiple introspectors, have a look atAnnotationIntrospectorPair
.- See Also:
-
defaultAttributes
Method for replacing defaultContextAttributes
that the mapper uses: usually one initialized with a set of default shared attributes, but potentially also with a custom implementation.NOTE: instance specified will need to be thread-safe for usage, similar to the default (
ContextAttributes.Impl
).- Parameters:
attrs
- Default instance to use: may not benull
.- Returns:
- This Builder instance to allow call chaining
-
typeFactory
-
subtypeResolver
-
visibility
-
visibility
-
handlerInstantiator
Method for configuringHandlerInstantiator
to use for creating instances of handlers (such as serializers, deserializers, type and type id resolvers), given a class.- Parameters:
hi
- Instantiator to use; if null, use the default implementation- Returns:
- Builder instance itself to allow chaining
-
propertyNamingStrategy
Method for configuringPropertyNamingStrategy
to use for adapting POJO property names (internal) into content property names (external)- Parameters:
s
- Strategy instance to use; if null, use the default implementation- Returns:
- Builder instance itself to allow chaining
-
accessorNaming
Method for configuringAccessorNamingStrategy
to use for auto-detecting accessor ("getter") and mutator ("setter") methods based on naming of methods.- Parameters:
s
- Strategy instance to use; if null, use the default implementation- Returns:
- Builder instance itself to allow chaining
- Since:
- 2.12
-
serializerFactory
-
filterProvider
Method for configuring this mapper to use specifiedFilterProvider
for mapping Filter Ids to actual filter instances.Note that usually it is better to use method in
ObjectWriter
, but sometimes this method is more convenient. For example, some frameworks only allow configuring of ObjectMapper instances and notObjectWriter
s. -
defaultPrettyPrinter
-
injectableValues
-
nodeFactory
-
constructorDetector
Method for specifyingConstructorDetector
to use for determining some aspects of creator auto-detection (specifically auto-detection of constructor, and in particular behavior with single-argument constructors).- Since:
- 2.12
-
addHandler
Method used for adding aDeserializationProblemHandler
for this builder, at the head of the list (meaning it has priority over handler registered earlier). -
clearProblemHandlers
Method that may be used to remove allDeserializationProblemHandler
s added to this builder (if any). -
defaultSetterInfo
-
defaultMergeable
Method for setting default Setter configuration, regarding things like merging, null-handling; used for properties for which there are no per-type or per-property overrides (via annotations or config overrides). -
defaultLeniency
Method for setting default Setter configuration, regarding things like merging, null-handling; used for properties for which there are no per-type or per-property overrides (via annotations or config overrides). -
defaultDateFormat
Method for configuring the defaultDateFormat
to use when serializing time values as Strings, and deserializing from JSON Strings. If you need per-request configuration, factory methods inObjectReader
andObjectWriter
instead. -
defaultTimeZone
Method for overriding default TimeZone to use for formatting. Default value used is UTC (NOT default TimeZone of JVM). -
defaultLocale
Method for overriding default locale to use for formatting. Default value used isLocale.getDefault()
. -
defaultBase64Variant
Method that will configure defaultBase64Variant
thatbyte[]
serializers and deserializers will use.- Parameters:
v
- Base64 variant to use- Returns:
- This builder instance to allow call chaining
-
serializationInclusion
Method for configured default property inclusion to use for serialization.- Parameters:
incl
- Default property inclusion to set- Returns:
- This builder instance to allow call chaining
-
defaultPropertyInclusion
Method for configured default property inclusion to use for serialization.- Parameters:
incl
- Default property inclusion to set- Returns:
- This builder instance to allow call chaining
- Since:
- 2.11
-
addMixIn
Method to use for defining mix-in annotations to use for augmenting annotations that classes have, for purpose of configuration serialization and/or deserialization processing. Mixing in is done when introspecting class annotations and properties. Annotations from "mixin" class (and its supertypes) will override annotations that target classes (and their super-types) have.Note that standard mixin handler implementations will only allow a single mix-in source class per target, so if there was a previous mix-in defined target it will be cleared. This also means that you can remove mix-in definition by specifying
mixinSource
ofnull
(although preferred mechanism isremoveMixIn(java.lang.Class<?>)
)- Parameters:
target
- Target class on which to add annotationsmixinSource
- Class that has annotations to add- Returns:
- This builder instance to allow call chaining
-
removeMixIn
Method that allows making sure that specifiedtarget
class does not have associated mix-in annotations: basically can be used to undo an earlier call toaddMixIn(java.lang.Class<?>, java.lang.Class<?>)
.NOTE: removing mix-ins for given class does not try to remove possible mix-ins for any of its super classes and super interfaces; only direct mix-in addition, if any, is removed.
- Parameters:
target
- Target class for which no mix-ins should remain after call- Returns:
- This builder instance to allow call chaining
- Since:
- 2.13
-
registerSubtypes
-
registerSubtypes
-
registerSubtypes
-
polymorphicTypeValidator
Method for assigningPolymorphicTypeValidator
to use for validating subtypes when using Class name - based polymorphic deserialization using annotations (validator used with "Default Typing" is specified by passing inactivateDefaultTyping(PolymorphicTypeValidator)
instead).Validator will be called on validating types for which no default databind deserializer, or module-provided deserializer is found: typically this includes "POJO" (aka Bean) types, but not (for example) most container types.
- Since:
- 2.10
-
activateDefaultTyping
Convenience method that is equivalent to callingactivateDefaultTyping(subtypeValidator, DefaultTyping.OBJECT_AND_NON_CONCRETE);
NOTE: choice of
PolymorphicTypeValidator
to pass is critical for security as allowing all subtypes can be risky for untrusted content. -
activateDefaultTyping
public B activateDefaultTyping(PolymorphicTypeValidator subtypeValidator, ObjectMapper.DefaultTyping dti) Convenience method that is equivalent to callingactivateDefaultTyping(subtypeValidator, dti, JsonTypeInfo.As.WRAPPER_ARRAY);
NOTE: choice of
PolymorphicTypeValidator
to pass is critical for security as allowing all subtypes can be risky for untrusted content. -
activateDefaultTyping
public B activateDefaultTyping(PolymorphicTypeValidator subtypeValidator, ObjectMapper.DefaultTyping applicability, JsonTypeInfo.As includeAs) Method for enabling automatic inclusion of type information, needed for proper deserialization of polymorphic types (unless types have been annotated withJsonTypeInfo
).NOTE: use of
JsonTypeInfo.As#EXTERNAL_PROPERTY
NOT SUPPORTED; and attempts of do so will throw anIllegalArgumentException
to make this limitation explicit.NOTE: choice of
PolymorphicTypeValidator
to pass is critical for security as allowing all subtypes can be risky for untrusted content.- Parameters:
applicability
- Defines kinds of types for which additional type information is added; seeObjectMapper.DefaultTyping
for more information.
-
activateDefaultTypingAsProperty
public B activateDefaultTypingAsProperty(PolymorphicTypeValidator subtypeValidator, ObjectMapper.DefaultTyping applicability, String propertyName) Method for enabling automatic inclusion of type information -- needed for proper deserialization of polymorphic types (unless types have been annotated withJsonTypeInfo
) -- using "As.PROPERTY" inclusion mechanism and specified property name to use for inclusion (default being "@class" since default type information always uses class name as type identifier)NOTE: choice of
PolymorphicTypeValidator
to pass is critical for security as allowing all subtypes can be risky for untrusted content. -
deactivateDefaultTyping
Method for disabling automatic inclusion of type information; if so, only explicitly annotated types (ones withJsonTypeInfo
) will have additional embedded type information. -
setDefaultTyping
Method for enabling automatic inclusion of type information, using specified handler object for determining which types this affects, as well as details of how information is embedded.NOTE: use of Default Typing can be a potential security risk if incoming content comes from untrusted sources, so care should be taken to use a
TypeResolverBuilder
that can limit allowed classes to deserialize. Note in particular thatStdTypeResolverBuilder
DOES NOT limit applicability but creates type (de)serializers for all types.- Parameters:
typer
- Type information inclusion handler- Since:
- 2.12
-
_this
-