com.fasterxml.jackson.databind.cfg

Class MapperBuilder<M extends ObjectMapper,B extends MapperBuilder<M,B>>

  • Direct Known Subclasses:
    JsonMapper.Builder


    public abstract class MapperBuilder<M extends ObjectMapper,B extends MapperBuilder<M,B>>
    extends Object
    Jackson 3 will introduce fully immutable, builder-based system for constructing ObjectMappers. 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
    • Constructor Detail

      • MapperBuilder

        protected MapperBuilder(M mapper)
    • 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(com.fasterxml.jackson.core.JsonParser.Feature f)
      • isEnabled

        public boolean isEnabled(com.fasterxml.jackson.core.JsonGenerator.Feature f)
      • streamFactory

        public com.fasterxml.jackson.core.TokenStreamFactory streamFactory()
      • configure

        public B configure(MapperFeature feature,
                           boolean state)
      • enable

        public B enable(com.fasterxml.jackson.core.JsonParser.Feature... features)
      • disable

        public B disable(com.fasterxml.jackson.core.JsonParser.Feature... features)
      • configure

        public B configure(com.fasterxml.jackson.core.JsonParser.Feature feature,
                           boolean state)
      • enable

        public B enable(com.fasterxml.jackson.core.JsonGenerator.Feature... features)
      • disable

        public B disable(com.fasterxml.jackson.core.JsonGenerator.Feature... features)
      • configure

        public B configure(com.fasterxml.jackson.core.JsonGenerator.Feature feature,
                           boolean state)
      • enable

        public B enable(com.fasterxml.jackson.core.StreamReadFeature... features)
      • disable

        public B disable(com.fasterxml.jackson.core.StreamReadFeature... features)
      • configure

        public B configure(com.fasterxml.jackson.core.StreamReadFeature feature,
                           boolean state)
      • enable

        public B enable(com.fasterxml.jackson.core.StreamWriteFeature... features)
      • disable

        public B disable(com.fasterxml.jackson.core.StreamWriteFeature... features)
      • configure

        public B configure(com.fasterxml.jackson.core.StreamWriteFeature feature,
                           boolean state)
      • addModule

        public B addModule(Module module)
      • addModules

        public B addModules(Module... modules)
      • findModules

        public static List<Module> findModules()
        Method for locating available methods, using JDK ServiceLoader facility, along with module-provided SPI.

        Note that method does not do any caching, so calls should be considered potentially expensive.

      • findModules

        public static List<Module> findModules(ClassLoader classLoader)
        Method for locating available methods, using JDK ServiceLoader 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.

      • visibility

        public B visibility(com.fasterxml.jackson.annotation.PropertyAccessor forMethod,
                            com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility visibility)
      • handlerInstantiator

        public 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.
        Parameters:
        hi - Instantiator to use; if null, use the default implementation
      • filterProvider

        public B filterProvider(FilterProvider prov)
        Method for configuring this mapper to use specified 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 ObjectWriters.

      • defaultPrettyPrinter

        public B defaultPrettyPrinter(com.fasterxml.jackson.core.PrettyPrinter pp)
      • clearProblemHandlers

        public B clearProblemHandlers()
        Method that may be used to remove all DeserializationProblemHandlers added to this builder (if any).
      • defaultDateFormat

        public B defaultDateFormat(DateFormat df)
        Method for configuring the default 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.
      • defaultTimeZone

        public B defaultTimeZone(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(Locale locale)
        Method for overriding default locale to use for formatting. Default value used is Locale.getDefault().
      • defaultBase64Variant

        public B defaultBase64Variant(com.fasterxml.jackson.core.Base64Variant v)
        Method that will configure default Base64Variant that byte[] serializers and deserializers will use.
        Parameters:
        v - Base64 variant to use
        Returns:
        This mapper, for convenience to allow chaining
      • serializationInclusion

        public B serializationInclusion(com.fasterxml.jackson.annotation.JsonInclude.Include incl)
      • addMixIn

        public 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. 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 of null

      • registerSubtypes

        public B registerSubtypes(Class<?>... subtypes)
      • registerSubtypes

        public B registerSubtypes(NamedType... subtypes)
      • enableDefaultTyping

        public B enableDefaultTyping(PolymorphicTypeValidator subtypeValidator)
        Convenience method that is equivalent to calling
          enableDefaultTyping(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.

      • enableDefaultTyping

        public B enableDefaultTyping(PolymorphicTypeValidator subtypeValidator,
                                     ObjectMapper.DefaultTyping dti)
        Convenience method that is equivalent to calling
          enableDefaultTyping(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.

      • enableDefaultTyping

        public B enableDefaultTyping(PolymorphicTypeValidator subtypeValidator,
                                     ObjectMapper.DefaultTyping applicability,
                                     com.fasterxml.jackson.annotation.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).

        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.

        Parameters:
        applicability - Defines kinds of types for which additional type information is added; see ObjectMapper.DefaultTyping for more information.
      • enableDefaultTypingAsProperty

        public B enableDefaultTypingAsProperty(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)

        NOTE: choice of PolymorphicTypeValidator to pass is critical for security as allowing all subtypes can be risky for untrusted content.

      • disableDefaultTyping

        public B disableDefaultTyping()
        Method for disabling automatic inclusion of type information; if so, only explicitly annotated types (ones with JsonTypeInfo) will have additional embedded type information.
      • _this

        protected final B _this()

Copyright © 2008–2019 FasterXML. All rights reserved.