Class MapperBuilder<M extends ObjectMapper,B extends MapperBuilder<M,B>>
- java.lang.Object
-
- com.fasterxml.jackson.databind.cfg.MapperBuilder<M,B>
-
- Direct Known Subclasses:
JsonMapper.Builder
public abstract class MapperBuilder<M extends ObjectMapper,B extends MapperBuilder<M,B>> extends java.lang.Object
Jackson 3 will introduce fully immutable, builder-based system for constructingObjectMapper
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
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description B
activateDefaultTyping(PolymorphicTypeValidator subtypeValidator)
Convenience method that is equivalent to callingB
activateDefaultTyping(PolymorphicTypeValidator subtypeValidator, ObjectMapper.DefaultTyping dti)
Convenience method that is equivalent to callingB
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
).B
activateDefaultTypingAsProperty(PolymorphicTypeValidator subtypeValidator, ObjectMapper.DefaultTyping applicability, java.lang.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)B
addHandler(DeserializationProblemHandler h)
Method used for adding aDeserializationProblemHandler
for this builder, at the head of the list (meaning it has priority over handler registered earlier).B
addMixIn(java.lang.Class<?> target, java.lang.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(Module... modules)
B
addModules(java.lang.Iterable<? extends Module> modules)
B
annotationIntrospector(AnnotationIntrospector intr)
Method for replacingAnnotationIntrospector
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 allDeserializationProblemHandler
s added to this builder (if any).B
configure(JsonGenerator.Feature feature, boolean state)
B
configure(JsonParser.Feature feature, boolean state)
B
configure(StreamReadFeature feature, boolean state)
B
configure(StreamWriteFeature feature, boolean state)
B
configure(DeserializationFeature feature, boolean state)
B
configure(MapperFeature feature, boolean state)
B
configure(SerializationFeature feature, boolean state)
B
deactivateDefaultTyping()
Method for disabling automatic inclusion of type information; if so, only explicitly annotated types (ones withJsonTypeInfo
) will have additional embedded type information.B
defaultBase64Variant(Base64Variant v)
Method that will configure defaultBase64Variant
thatbyte[]
serializers and deserializers will use.B
defaultDateFormat(java.text.DateFormat df)
Method for configuring the defaultDateFormat
to use when serializing time values as Strings, and deserializing from JSON Strings.B
defaultLeniency(java.lang.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(java.util.Locale locale)
Method for overriding default locale to use for formatting.B
defaultMergeable(java.lang.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(PrettyPrinter pp)
B
defaultSetterInfo(JsonSetter.Value v)
B
defaultTimeZone(java.util.TimeZone tz)
Method for overriding default TimeZone to use for formatting.B
disable(JsonGenerator.Feature... features)
B
disable(JsonParser.Feature... features)
B
disable(StreamReadFeature... features)
B
disable(StreamWriteFeature... features)
B
disable(DeserializationFeature... features)
B
disable(MapperFeature... features)
B
disable(SerializationFeature... features)
B
enable(JsonGenerator.Feature... features)
B
enable(JsonParser.Feature... features)
B
enable(StreamReadFeature... features)
B
enable(StreamWriteFeature... features)
B
enable(DeserializationFeature... features)
B
enable(MapperFeature... features)
B
enable(SerializationFeature... features)
B
filterProvider(FilterProvider prov)
Method for configuring this mapper to use specifiedFilterProvider
for mapping Filter Ids to actual filter instances.B
findAndAddModules()
Convenience method that is functionally equivalent to:addModules(builder.findModules());
static java.util.List<Module>
findModules()
Method for locating available methods, using JDKServiceLoader
facility, along with module-provided SPI.static java.util.List<Module>
findModules(java.lang.ClassLoader classLoader)
Method for locating available methods, using JDKServiceLoader
facility, along with module-provided SPI.B
handlerInstantiator(HandlerInstantiator hi)
Method for configuringHandlerInstantiator
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(JsonGenerator.Feature f)
boolean
isEnabled(JsonParser.Feature f)
boolean
isEnabled(DeserializationFeature f)
boolean
isEnabled(MapperFeature f)
boolean
isEnabled(SerializationFeature f)
B
nodeFactory(JsonNodeFactory f)
B
polymorphicTypeValidator(PolymorphicTypeValidator ptv)
B
propertyNamingStrategy(PropertyNamingStrategy s)
B
registerSubtypes(NamedType... subtypes)
B
registerSubtypes(java.lang.Class<?>... subtypes)
B
registerSubtypes(java.util.Collection<java.lang.Class<?>> subtypes)
B
serializationInclusion(JsonInclude.Include incl)
B
serializerFactory(SerializerFactory f)
TokenStreamFactory
streamFactory()
B
subtypeResolver(SubtypeResolver r)
B
typeFactory(TypeFactory f)
B
visibility(PropertyAccessor forMethod, JsonAutoDetect.Visibility visibility)
B
visibility(VisibilityChecker<?> vc)
-
-
-
Method Detail
-
build
public M 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
public boolean isEnabled(MapperFeature f)
-
isEnabled
public boolean isEnabled(DeserializationFeature f)
-
isEnabled
public boolean isEnabled(SerializationFeature f)
-
isEnabled
public boolean isEnabled(JsonParser.Feature f)
-
isEnabled
public boolean isEnabled(JsonGenerator.Feature f)
-
streamFactory
public TokenStreamFactory streamFactory()
-
enable
public B enable(MapperFeature... features)
-
disable
public B disable(MapperFeature... features)
-
configure
public B configure(MapperFeature feature, boolean state)
-
enable
public B enable(SerializationFeature... features)
-
disable
public B disable(SerializationFeature... features)
-
configure
public B configure(SerializationFeature feature, boolean state)
-
enable
public B enable(DeserializationFeature... features)
-
disable
public B disable(DeserializationFeature... features)
-
configure
public B configure(DeserializationFeature feature, boolean state)
-
enable
public B enable(JsonParser.Feature... features)
-
disable
public B disable(JsonParser.Feature... features)
-
configure
public B configure(JsonParser.Feature feature, boolean state)
-
enable
public B enable(JsonGenerator.Feature... features)
-
disable
public B disable(JsonGenerator.Feature... features)
-
configure
public B configure(JsonGenerator.Feature feature, boolean state)
-
enable
public B enable(StreamReadFeature... features)
-
disable
public B disable(StreamReadFeature... features)
-
configure
public B configure(StreamReadFeature feature, boolean state)
-
enable
public B enable(StreamWriteFeature... features)
-
disable
public B disable(StreamWriteFeature... features)
-
configure
public B configure(StreamWriteFeature feature, boolean state)
-
findModules
public static java.util.List<Module> 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
public static java.util.List<Module> findModules(java.lang.ClassLoader classLoader)
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
public B 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
public B annotationIntrospector(AnnotationIntrospector intr)
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:
AnnotationIntrospectorPair
-
nodeFactory
public B nodeFactory(JsonNodeFactory f)
-
typeFactory
public B typeFactory(TypeFactory f)
-
subtypeResolver
public B subtypeResolver(SubtypeResolver r)
-
visibility
public B visibility(VisibilityChecker<?> vc)
-
visibility
public B visibility(PropertyAccessor forMethod, JsonAutoDetect.Visibility visibility)
-
handlerInstantiator
public B handlerInstantiator(HandlerInstantiator hi)
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
-
propertyNamingStrategy
public B propertyNamingStrategy(PropertyNamingStrategy s)
-
serializerFactory
public B serializerFactory(SerializerFactory f)
-
filterProvider
public B filterProvider(FilterProvider prov)
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
public B defaultPrettyPrinter(PrettyPrinter pp)
-
injectableValues
public B injectableValues(InjectableValues v)
-
addHandler
public B addHandler(DeserializationProblemHandler h)
Method used for adding aDeserializationProblemHandler
for this builder, at the head of the list (meaning it has priority over handler registered earlier).
-
clearProblemHandlers
public B clearProblemHandlers()
Method that may be used to remove allDeserializationProblemHandler
s added to this builder (if any).
-
defaultSetterInfo
public B defaultSetterInfo(JsonSetter.Value v)
-
defaultMergeable
public B defaultMergeable(java.lang.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).
-
defaultLeniency
public B defaultLeniency(java.lang.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).
-
defaultDateFormat
public B defaultDateFormat(java.text.DateFormat df)
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
public B defaultTimeZone(java.util.TimeZone tz)
Method for overriding default TimeZone to use for formatting. Default value used is UTC (NOT default TimeZone of JVM).
-
defaultLocale
public B defaultLocale(java.util.Locale locale)
Method for overriding default locale to use for formatting. Default value used isLocale.getDefault()
.
-
defaultBase64Variant
public B defaultBase64Variant(Base64Variant v)
Method that will configure defaultBase64Variant
thatbyte[]
serializers and deserializers will use.- Parameters:
v
- Base64 variant to use- Returns:
- This mapper, for convenience to allow chaining
-
serializationInclusion
public B serializationInclusion(JsonInclude.Include incl)
-
addMixIn
public B addMixIn(java.lang.Class<?> target, java.lang.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. 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
-
registerSubtypes
public B registerSubtypes(java.lang.Class<?>... subtypes)
-
registerSubtypes
public B registerSubtypes(java.util.Collection<java.lang.Class<?>> subtypes)
-
polymorphicTypeValidator
public B polymorphicTypeValidator(PolymorphicTypeValidator ptv)
- Since:
- 2.10
-
activateDefaultTyping
public B activateDefaultTyping(PolymorphicTypeValidator subtypeValidator)
Convenience method that is equivalent to callingenableDefaultTyping(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 callingenableDefaultTyping(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, java.lang.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
public B deactivateDefaultTyping()
Method for disabling automatic inclusion of type information; if so, only explicitly annotated types (ones withJsonTypeInfo
) will have additional embedded type information.
-
-