public abstract class MapperBuilder<M extends ObjectMapper,B extends MapperBuilder<M,B>> extends Object
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.Modifier | Constructor and Description |
---|---|
protected |
MapperBuilder(M mapper) |
Modifier and Type | Method and Description |
---|---|
protected B |
_this() |
B |
accessorNaming(AccessorNamingStrategy.Provider s)
Method for configuring
AccessorNamingStrategy to use for auto-detecting
accessor ("getter") and mutator ("setter") methods based on naming of methods. |
B |
activateDefaultTyping(PolymorphicTypeValidator subtypeValidator)
Convenience method that is equivalent to calling
|
B |
activateDefaultTyping(PolymorphicTypeValidator subtypeValidator,
ObjectMapper.DefaultTyping dti)
Convenience method that is equivalent to calling
|
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 with
JsonTypeInfo ). |
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 with
JsonTypeInfo ) --
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) |
B |
addHandler(DeserializationProblemHandler h)
Method used for adding a
DeserializationProblemHandler for this
builder, at the head of the list (meaning it has priority over handler
registered earlier). |
B |
addMixIn(Class<?> target,
Class<?> mixinSource)
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.
|
B |
addModule(Module module) |
B |
addModules(Iterable<? extends Module> modules) |
B |
addModules(Module... modules) |
B |
annotationIntrospector(AnnotationIntrospector intr)
Method for replacing
AnnotationIntrospector used by the
mapper instance to be built. |
M |
build()
Method to call to create actual mapper instance.
|
B |
clearProblemHandlers()
Method that may be used to remove all
DeserializationProblemHandler s added
to this builder (if any). |
B |
configure(DatatypeFeature feature,
boolean state) |
B |
configure(DeserializationFeature feature,
boolean state) |
B |
configure(com.fasterxml.jackson.core.JsonGenerator.Feature feature,
boolean state) |
B |
configure(com.fasterxml.jackson.core.JsonParser.Feature feature,
boolean state) |
B |
configure(MapperFeature feature,
boolean state) |
B |
configure(SerializationFeature feature,
boolean state) |
B |
configure(com.fasterxml.jackson.core.StreamReadFeature feature,
boolean state) |
B |
configure(com.fasterxml.jackson.core.StreamWriteFeature feature,
boolean state) |
B |
constructorDetector(ConstructorDetector cd)
Method for specifying
ConstructorDetector to use for
determining some aspects of creator auto-detection (specifically
auto-detection of constructor, and in particular behavior with
single-argument constructors). |
B |
deactivateDefaultTyping()
Method for disabling automatic inclusion of type information; if so, only
explicitly annotated types (ones with
JsonTypeInfo ) will have
additional embedded type information. |
B |
defaultAttributes(ContextAttributes attrs)
Method for replacing default
ContextAttributes that the mapper
uses: usually one initialized with a set of default shared attributes, but
potentially also with a custom implementation. |
B |
defaultBase64Variant(com.fasterxml.jackson.core.Base64Variant v)
Method that will configure default
Base64Variant that
byte[] serializers and deserializers will use. |
B |
defaultDateFormat(DateFormat df)
Method for configuring the default
DateFormat to use when serializing time
values as Strings, and deserializing from JSON Strings. |
B |
defaultLeniency(Boolean b)
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).
|
B |
defaultLocale(Locale locale)
Method for overriding default locale to use for formatting.
|
B |
defaultMergeable(Boolean b)
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).
|
B |
defaultPrettyPrinter(com.fasterxml.jackson.core.PrettyPrinter pp) |
B |
defaultPropertyInclusion(JsonInclude.Value incl)
Method for configured default property inclusion to use for serialization.
|
B |
defaultSetterInfo(JsonSetter.Value v) |
B |
defaultTimeZone(TimeZone tz)
Method for overriding default TimeZone to use for formatting.
|
B |
disable(DatatypeFeature... features) |
B |
disable(DeserializationFeature... features) |
B |
disable(com.fasterxml.jackson.core.JsonGenerator.Feature... features) |
B |
disable(com.fasterxml.jackson.core.JsonParser.Feature... features) |
B |
disable(MapperFeature... features) |
B |
disable(SerializationFeature... features) |
B |
disable(com.fasterxml.jackson.core.StreamReadFeature... features) |
B |
disable(com.fasterxml.jackson.core.StreamWriteFeature... features) |
B |
enable(DatatypeFeature... features) |
B |
enable(DeserializationFeature... features) |
B |
enable(com.fasterxml.jackson.core.JsonGenerator.Feature... features) |
B |
enable(com.fasterxml.jackson.core.JsonParser.Feature... features) |
B |
enable(MapperFeature... features) |
B |
enable(SerializationFeature... features) |
B |
enable(com.fasterxml.jackson.core.StreamReadFeature... features) |
B |
enable(com.fasterxml.jackson.core.StreamWriteFeature... features) |
B |
filterProvider(FilterProvider prov)
Method for configuring this mapper to use specified
FilterProvider for
mapping Filter Ids to actual filter instances. |
B |
findAndAddModules()
Convenience method that is functionally equivalent to:
addModules(builder.findModules());
|
static List<Module> |
findModules()
Method for locating available methods, using JDK
ServiceLoader
facility, along with module-provided SPI. |
static List<Module> |
findModules(ClassLoader classLoader)
Method for locating available methods, using JDK
ServiceLoader
facility, along with module-provided SPI. |
B |
handlerInstantiator(HandlerInstantiator hi)
Method for configuring
HandlerInstantiator to use for creating
instances of handlers (such as serializers, deserializers, type and type
id resolvers), given a class. |
B |
injectableValues(InjectableValues v) |
boolean |
isEnabled(DeserializationFeature f) |
boolean |
isEnabled(com.fasterxml.jackson.core.JsonGenerator.Feature f) |
boolean |
isEnabled(com.fasterxml.jackson.core.JsonParser.Feature f) |
boolean |
isEnabled(MapperFeature f) |
boolean |
isEnabled(SerializationFeature f) |
B |
nodeFactory(JsonNodeFactory f) |
B |
polymorphicTypeValidator(PolymorphicTypeValidator ptv)
Method for assigning
PolymorphicTypeValidator to use for validating
subtypes when using Class name - based polymorphic deserialization
using annotations (validator used with "Default Typing" is specified by
passing in activateDefaultTyping(PolymorphicTypeValidator) instead). |
B |
propertyNamingStrategy(PropertyNamingStrategy s)
Method for configuring
PropertyNamingStrategy to use for adapting
POJO property names (internal) into content property names (external) |
B |
registerSubtypes(Class<?>... subtypes) |
B |
registerSubtypes(Collection<Class<?>> subtypes) |
B |
registerSubtypes(NamedType... subtypes) |
B |
removeMixIn(Class<?> target)
Method that allows making sure that specified
target class
does not have associated mix-in annotations: basically can be used
to undo an earlier call to addMixIn(java.lang.Class<?>, java.lang.Class<?>) . |
B |
serializationInclusion(JsonInclude.Include incl)
Method for configured default property inclusion to use for serialization.
|
B |
serializerFactory(SerializerFactory f) |
B |
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.
|
com.fasterxml.jackson.core.TokenStreamFactory |
streamFactory() |
B |
subtypeResolver(SubtypeResolver r) |
B |
typeFactory(TypeFactory f) |
B |
visibility(PropertyAccessor forMethod,
JsonAutoDetect.Visibility visibility) |
B |
visibility(VisibilityChecker<?> vc) |
B |
withCoercionConfig(Class<?> forType,
Consumer<MutableCoercionConfig> handler)
Method for changing coercion config for specific physical type, through
callback to specific handler.
|
B |
withCoercionConfig(LogicalType forType,
Consumer<MutableCoercionConfig> handler)
Method for changing coercion config for specific logical types, through
callback to specific handler.
|
B |
withCoercionConfigDefaults(Consumer<MutableCoercionConfig> handler)
Method for changing target-type-independent coercion configuration defaults.
|
B |
withConfigOverride(Class<?> forType,
Consumer<MutableConfigOverride> handler)
Method for changing config overrides for specific type, through
callback to specific handler.
|
protected final M extends ObjectMapper _mapper
protected MapperBuilder(M mapper)
public M build()
Implementation detail: in 2.10 (but not 3.x) underlying mapper is eagerly constructed when builder is constructed, and method simply returns that instance.
public boolean isEnabled(MapperFeature f)
public boolean isEnabled(DeserializationFeature f)
public boolean isEnabled(SerializationFeature f)
public boolean isEnabled(com.fasterxml.jackson.core.JsonParser.Feature f)
public boolean isEnabled(com.fasterxml.jackson.core.JsonGenerator.Feature f)
public com.fasterxml.jackson.core.TokenStreamFactory streamFactory()
public B enable(MapperFeature... features)
public B disable(MapperFeature... features)
public B configure(MapperFeature feature, boolean state)
public B enable(SerializationFeature... features)
public B disable(SerializationFeature... features)
public B configure(SerializationFeature feature, boolean state)
public B enable(DeserializationFeature... features)
public B disable(DeserializationFeature... features)
public B configure(DeserializationFeature feature, boolean state)
public B enable(DatatypeFeature... features)
public B disable(DatatypeFeature... features)
public B configure(DatatypeFeature feature, boolean state)
public B enable(com.fasterxml.jackson.core.JsonParser.Feature... features)
public B disable(com.fasterxml.jackson.core.JsonParser.Feature... features)
public B configure(com.fasterxml.jackson.core.JsonParser.Feature feature, boolean state)
public B enable(com.fasterxml.jackson.core.JsonGenerator.Feature... features)
public B disable(com.fasterxml.jackson.core.JsonGenerator.Feature... features)
public B configure(com.fasterxml.jackson.core.JsonGenerator.Feature feature, boolean state)
public B enable(com.fasterxml.jackson.core.StreamReadFeature... features)
public B disable(com.fasterxml.jackson.core.StreamReadFeature... features)
public B configure(com.fasterxml.jackson.core.StreamReadFeature feature, boolean state)
public B enable(com.fasterxml.jackson.core.StreamWriteFeature... features)
public B disable(com.fasterxml.jackson.core.StreamWriteFeature... features)
public B configure(com.fasterxml.jackson.core.StreamWriteFeature feature, boolean state)
public B withConfigOverride(Class<?> forType, Consumer<MutableConfigOverride> handler)
forType
- Type to change config overrides forhandler
- Function to call with MutableConfigOverride
public B withCoercionConfig(LogicalType forType, Consumer<MutableCoercionConfig> handler)
public B withCoercionConfig(Class<?> forType, Consumer<MutableCoercionConfig> handler)
public B withCoercionConfigDefaults(Consumer<MutableCoercionConfig> handler)
public static List<Module> findModules()
ServiceLoader
facility, along with module-provided SPI.
Note that method does not do any caching, so calls should be considered potentially expensive.
public static List<Module> findModules(ClassLoader classLoader)
ServiceLoader
facility, along with module-provided SPI.
Note that method does not do any caching, so calls should be considered potentially expensive.
public B findAndAddModules()
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.
public B annotationIntrospector(AnnotationIntrospector intr)
AnnotationIntrospector
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 at AnnotationIntrospectorPair
.AnnotationIntrospectorPair
public B defaultAttributes(ContextAttributes attrs)
ContextAttributes
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
).
attrs
- Default instance to use: may not be null
.public B typeFactory(TypeFactory f)
public B subtypeResolver(SubtypeResolver r)
public B visibility(VisibilityChecker<?> vc)
public B visibility(PropertyAccessor forMethod, JsonAutoDetect.Visibility visibility)
public B handlerInstantiator(HandlerInstantiator hi)
HandlerInstantiator
to use for creating
instances of handlers (such as serializers, deserializers, type and type
id resolvers), given a class.hi
- Instantiator to use; if null, use the default implementationpublic B propertyNamingStrategy(PropertyNamingStrategy s)
PropertyNamingStrategy
to use for adapting
POJO property names (internal) into content property names (external)s
- Strategy instance to use; if null, use the default implementationpublic B accessorNaming(AccessorNamingStrategy.Provider s)
AccessorNamingStrategy
to use for auto-detecting
accessor ("getter") and mutator ("setter") methods based on naming of methods.s
- Strategy instance to use; if null, use the default implementationpublic B serializerFactory(SerializerFactory f)
public B filterProvider(FilterProvider prov)
FilterProvider
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 not ObjectWriter
s.
public B defaultPrettyPrinter(com.fasterxml.jackson.core.PrettyPrinter pp)
public B injectableValues(InjectableValues v)
public B nodeFactory(JsonNodeFactory f)
public B constructorDetector(ConstructorDetector cd)
ConstructorDetector
to use for
determining some aspects of creator auto-detection (specifically
auto-detection of constructor, and in particular behavior with
single-argument constructors).public B addHandler(DeserializationProblemHandler h)
DeserializationProblemHandler
for this
builder, at the head of the list (meaning it has priority over handler
registered earlier).public B clearProblemHandlers()
DeserializationProblemHandler
s added
to this builder (if any).public B defaultSetterInfo(JsonSetter.Value v)
public B defaultMergeable(Boolean b)
public B defaultLeniency(Boolean b)
public B defaultDateFormat(DateFormat df)
DateFormat
to use when serializing time
values as Strings, and deserializing from JSON Strings.
If you need per-request configuration, factory methods in
ObjectReader
and ObjectWriter
instead.public B defaultTimeZone(TimeZone tz)
public B defaultLocale(Locale locale)
Locale.getDefault()
.public B defaultBase64Variant(com.fasterxml.jackson.core.Base64Variant v)
Base64Variant
that
byte[]
serializers and deserializers will use.v
- Base64 variant to usepublic B serializationInclusion(JsonInclude.Include incl)
incl
- Default property inclusion to setpublic B defaultPropertyInclusion(JsonInclude.Value incl)
incl
- Default property inclusion to setpublic B addMixIn(Class<?> target, Class<?> mixinSource)
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
of null
(although preferred mechanism is removeMixIn(java.lang.Class<?>)
)
target
- Target class on which to add annotationsmixinSource
- Class that has annotations to addpublic B removeMixIn(Class<?> target)
target
class
does not have associated mix-in annotations: basically can be used
to undo an earlier call to addMixIn(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.
target
- Target class for which no mix-ins should remain after callpublic B registerSubtypes(Collection<Class<?>> subtypes)
public B polymorphicTypeValidator(PolymorphicTypeValidator ptv)
PolymorphicTypeValidator
to use for validating
subtypes when using Class name - based polymorphic deserialization
using annotations (validator used with "Default Typing" is specified by
passing in activateDefaultTyping(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.
public B activateDefaultTyping(PolymorphicTypeValidator subtypeValidator)
activateDefaultTyping(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.
public B activateDefaultTyping(PolymorphicTypeValidator subtypeValidator, ObjectMapper.DefaultTyping dti)
activateDefaultTyping(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.
public B activateDefaultTyping(PolymorphicTypeValidator subtypeValidator, ObjectMapper.DefaultTyping applicability, JsonTypeInfo.As includeAs)
JsonTypeInfo
).
NOTE: use of JsonTypeInfo.As#EXTERNAL_PROPERTY
NOT SUPPORTED;
and attempts of do so will throw an IllegalArgumentException
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.
applicability
- Defines kinds of types for which additional type information
is added; see ObjectMapper.DefaultTyping
for more information.public B activateDefaultTypingAsProperty(PolymorphicTypeValidator subtypeValidator, ObjectMapper.DefaultTyping applicability, String propertyName)
JsonTypeInfo
) --
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.
public B deactivateDefaultTyping()
JsonTypeInfo
) will have
additional embedded type information.public B setDefaultTyping(TypeResolverBuilder<?> typer)
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 that
StdTypeResolverBuilder
DOES NOT limit applicability but creates type (de)serializers for all
types.
typer
- Type information inclusion handlerprotected final B _this()
Copyright © 2008–2022 FasterXML. All rights reserved.