com.fasterxml.jackson.databind

Class SerializerProvider

  • Direct Known Subclasses:
    DefaultSerializerProvider


    public abstract class SerializerProvider
    extends DatabindContext
    Class that defines API used by ObjectMapper and JsonSerializers to obtain serializers capable of serializing instances of specific types; as well as the default implementation of the functionality.

    Provider handles caching aspects of serializer handling; all construction details are delegated to SerializerFactory instance.

    Object life-cycle is such that an initial instance ("blueprint") is created and referenced by ObjectMapper and ObjectWriter intances; but for actual usage, a configured instance is created by using a create method in sub-class DefaultSerializerProvider. Only this instance can be used for actual serialization calls; blueprint object is only to be used for creating instances.

    • Field Detail

      • CACHE_UNKNOWN_MAPPINGS

        protected static final boolean CACHE_UNKNOWN_MAPPINGS
        Setting for determining whether mappings for "unknown classes" should be cached for faster resolution. Usually this isn't needed, but maybe it is in some cases?
        See Also:
        Constant Field Values
      • DEFAULT_NULL_KEY_SERIALIZER

        public static final JsonSerializer<Object> DEFAULT_NULL_KEY_SERIALIZER
      • DEFAULT_UNKNOWN_SERIALIZER

        protected static final JsonSerializer<Object> DEFAULT_UNKNOWN_SERIALIZER
        Placeholder serializer used when java.lang.Object typed property is marked to be serialized.
        NOTE: starting with 2.6, this instance is NOT used for any other types, and separate instances are constructed for "empty" Beans.

        NOTE: changed to protected for 2.3; no need to be publicly available.

      • _config

        protected final SerializationConfig _config
        Serialization configuration to use for serialization processing.
      • _serializationView

        protected final Class<?> _serializationView
        View used for currently active serialization, if any. Only set for non-blueprint instances.
      • _serializerFactory

        protected final SerializerFactory _serializerFactory
        Factory used for constructing actual serializer instances. Only set for non-blueprint instances.
      • _serializerCache

        protected final SerializerCache _serializerCache
        Cache for doing type-to-value-serializer lookups.
      • _attributes

        protected transient ContextAttributes _attributes
        Lazily-constructed holder for per-call attributes. Only set for non-blueprint instances.
        Since:
        2.3
      • _unknownTypeSerializer

        protected JsonSerializer<Object> _unknownTypeSerializer
        Serializer that gets called for values of types for which no serializers can be constructed.

        The default serializer will simply thrown an exception.

      • _keySerializer

        protected JsonSerializer<Object> _keySerializer
        Serializer used to output non-null keys of Maps (which will get output as JSON Objects), if not null; if null, us the standard default key serializer.
      • _nullKeySerializer

        protected JsonSerializer<Object> _nullKeySerializer
        Serializer used to (try to) output a null key, due to an entry of Map having null key. The default implementation will throw an exception if this happens; alternative implementation (like one that would write an Empty String) can be defined.
      • _knownSerializers

        protected final ReadOnlyClassToSerializerMap _knownSerializers
        For fast lookups, we will have a local non-shared read-only map that contains serializers previously fetched.
      • _dateFormat

        protected DateFormat _dateFormat
        Lazily acquired and instantiated formatter object: initialized first time it is needed, reused afterwards. Used via instances (not blueprints), so that access need not be thread-safe.
      • _stdNullValueSerializer

        protected final boolean _stdNullValueSerializer
        Flag set to indicate that we are using vanilla null value serialization
        Since:
        2.3
    • Constructor Detail

      • SerializerProvider

        public SerializerProvider()
        Constructor for creating master (or "blue-print") provider object, which is only used as the template for constructing per-binding instances.
      • SerializerProvider

        protected SerializerProvider(SerializerProvider src,
                                     SerializationConfig config,
                                     SerializerFactory f)
        "Copy-constructor", used by sub-classes when creating actual non-blueprint instances to use.
        Parameters:
        src - Blueprint object used as the baseline for this instance
      • SerializerProvider

        protected SerializerProvider(SerializerProvider src)
        Copy-constructor used when making a copy of a blueprint instance.
        Since:
        2.5

Copyright © 2008–2021 FasterXML. All rights reserved.