com.fasterxml.jackson.databind.ser

## Class DefaultSerializerProvider

- java.lang.Object
- - com.fasterxml.jackson.databind.DatabindContext
  - - com.fasterxml.jackson.databind.SerializerProvider
    - - com.fasterxml.jackson.databind.ser.DefaultSerializerProvider

- All Implemented Interfaces:
    java.io.Serializable
  Direct Known Subclasses:
    DefaultSerializerProvider.Impl

      public abstract class DefaultSerializerProvider
      extends SerializerProvider
      implements java.io.Serializable

  Standard implementation used by `ObjectMapper`: adds methods only exposed to `ObjectMapper`, as well as constructors.

  Note that class is abstract just because it does not define `createInstance(com.fasterxml.jackson.databind.SerializationConfig, com.fasterxml.jackson.databind.ser.SerializerFactory)` method.

  Also note that all custom `SerializerProvider` implementations must sub-class this class: `ObjectMapper` requires this type, not basic provider type.

  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `DefaultSerializerProvider.Impl` Concrete implementation that defines factory method(s), defined as final.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected com.fasterxml.jackson.core.JsonGenerator` | `_generator` Generator used for serialization.
    `protected java.util.ArrayList<com.fasterxml.jackson.annotation.ObjectIdGenerator<?>>` | `_objectIdGenerators`
    `protected java.util.Map<java.lang.Object,WritableObjectId>` | `_seenObjectIds` Per-serialization map Object Ids that have seen so far, iff Object Id handling is enabled.

    - ### Fields inherited from class com.fasterxml.jackson.databind.SerializerProvider

      `_attributes, _config, _dateFormat, _keySerializer, _knownSerializers, _nullKeySerializer, _nullValueSerializer, _serializationView, _serializerCache, _serializerFactory, _stdNullValueSerializer, _unknownTypeSerializer, CACHE_UNKNOWN_MAPPINGS, DEFAULT_NULL_KEY_SERIALIZER, DEFAULT_UNKNOWN_SERIALIZER`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `DefaultSerializerProvider()`
    `protected` | `DefaultSerializerProvider(DefaultSerializerProvider src)`
    `protected` | `DefaultSerializerProvider(SerializerProvider src, SerializationConfig config, SerializerFactory f)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected java.util.Map<java.lang.Object,WritableObjectId>` | `_createObjectIdMap()` Overridable helper method used for creating `Map` used for storing mappings from serializable objects to their Object Ids.
    `protected void` | `_serializeNull(com.fasterxml.jackson.core.JsonGenerator gen)` Helper method called when root value to serialize is null
    `void` | `acceptJsonFormatVisitor(JavaType javaType, JsonFormatVisitorWrapper visitor)` The method to be called by `ObjectMapper` and `ObjectWriter` to to expose the format of the given to to the given visitor
    `int` | `cachedSerializersCount()` Method that can be used to determine how many serializers this provider is caching currently (if it does caching: default implementation does) Exact count depends on what kind of serializers get cached; default implementation caches all serializers, including ones that are eagerly constructed (for optimal access speed)
    `DefaultSerializerProvider` | `copy()` Method needed to ensure that `ObjectMapper.copy()` will work properly; specifically, that caches are cleared, but settings will otherwise remain identical; and that no sharing of state occurs.
    `abstract DefaultSerializerProvider` | `createInstance(SerializationConfig config, SerializerFactory jsf)` Method that sub-classes need to implement: used to create a non-blueprint instances from the blueprint.
    `WritableObjectId` | `findObjectId(java.lang.Object forPojo, com.fasterxml.jackson.annotation.ObjectIdGenerator<?> generatorType)` Method called to find the Object Id for given POJO, if one has been generated.
    `void` | `flushCachedSerializers()` Method that will drop all serializers currently cached by this provider.
    `JsonSchema` | `generateJsonSchema(java.lang.Class<?> type)` Deprecated. Should not be used any more
    `com.fasterxml.jackson.core.JsonGenerator` | `getGenerator()` Accessor for the `JsonGenerator` currently in use for serializing content.
    `boolean` | `hasSerializerFor(java.lang.Class<?> cls, java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> cause)` Method that can be called to see if this serializer provider can find a serializer for an instance of given class.
    `void` | `serializePolymorphic(com.fasterxml.jackson.core.JsonGenerator gen, java.lang.Object value, JavaType rootType, JsonSerializer<java.lang.Object> valueSer, TypeSerializer typeSer)` Alternate serialization call used for polymorphic types, when `TypeSerializer` is already known, but the actual serializer may or may not be.
    `void` | `serializePolymorphic(com.fasterxml.jackson.core.JsonGenerator gen, java.lang.Object value, TypeSerializer typeSer)` Deprecated. since 2.6; remove from 2.7 or later
    `JsonSerializer<java.lang.Object>` | `serializerInstance(Annotated annotated, java.lang.Object serDef)` Method that can be called to construct and configure serializer instance, either given a `Class` to instantiate (with default constructor), or an uninitialized serializer instance.
    `void` | `serializeValue(com.fasterxml.jackson.core.JsonGenerator gen, java.lang.Object value)` The method to be called by `ObjectMapper` and `ObjectWriter` for serializing given value, using serializers that this provider has access to (via caching and/or creating new serializers as need be).
    `void` | `serializeValue(com.fasterxml.jackson.core.JsonGenerator gen, java.lang.Object value, JavaType rootType)` The method to be called by `ObjectMapper` and `ObjectWriter` for serializing given value (assumed to be of specified root type, instead of runtime type of value), using serializers that this provider has access to (via caching and/or creating new serializers as need be),
    `void` | `serializeValue(com.fasterxml.jackson.core.JsonGenerator gen, java.lang.Object value, JavaType rootType, JsonSerializer<java.lang.Object> ser)` The method to be called by `ObjectWriter` for serializing given value (assumed to be of specified root type, instead of runtime type of value), when it may know specific `JsonSerializer` to use.

    - ### Methods inherited from class com.fasterxml.jackson.databind.SerializerProvider

      `_createAndCacheUntypedSerializer, _createAndCacheUntypedSerializer, _createUntypedSerializer, _dateFormat, _desc, _findExplicitUntypedSerializer, _handleContextualResolvable, _handleResolvable, _quotedString, _reportIncompatibleRootType, canOverrideAccessModifiers, defaultSerializeDateKey, defaultSerializeDateKey, defaultSerializeDateValue, defaultSerializeDateValue, defaultSerializeField, defaultSerializeNull, defaultSerializeValue, findKeySerializer, findKeySerializer, findNullKeySerializer, findNullValueSerializer, findPrimaryPropertySerializer, findPrimaryPropertySerializer, findTypedValueSerializer, findTypedValueSerializer, findTypeSerializer, findValueSerializer, findValueSerializer, findValueSerializer, findValueSerializer, getActiveView, getAnnotationIntrospector, getAttribute, getConfig, getDefaultNullKeySerializer, getDefaultNullValueSerializer, getDefaultPropertyFormat, getDefaultPropertyInclusion, getFilterProvider, getLocale, getSerializationView, getTimeZone, getTypeFactory, getUnknownTypeSerializer, handlePrimaryContextualization, handleSecondaryContextualization, hasSerializationFeatures, isEnabled, isEnabled, isUnknownTypeSerializer, mappingException, mappingException, reportBadPropertyDefinition, reportBadTypeDefinition, reportMappingProblem, reportMappingProblem, setAttribute, setDefaultKeySerializer, setNullKeySerializer, setNullValueSerializer`

    - ### Methods inherited from class com.fasterxml.jackson.databind.DatabindContext

      `constructSpecializedType, constructType, converterInstance, objectIdGeneratorInstance, objectIdResolverInstance`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### _seenObjectIds

          protected transient java.util.Map<java.lang.Object,WritableObjectId> _seenObjectIds

      Per-serialization map Object Ids that have seen so far, iff Object Id handling is enabled.

    - #### _objectIdGenerators

          protected transient java.util.ArrayList<com.fasterxml.jackson.annotation.ObjectIdGenerator<?>> _objectIdGenerators

    - #### _generator

          protected transient com.fasterxml.jackson.core.JsonGenerator _generator

      Generator used for serialization. Needed mostly for error reporting purposes.
      Since:
        2.8

  - ### Constructor Detail

    - #### DefaultSerializerProvider

          protected DefaultSerializerProvider()

    - #### DefaultSerializerProvider

          protected DefaultSerializerProvider(SerializerProvider src,
                                   SerializationConfig config,
                                   SerializerFactory f)

    - #### DefaultSerializerProvider

          protected DefaultSerializerProvider(DefaultSerializerProvider src)

  - ### Method Detail

    - #### createInstance

          public abstract DefaultSerializerProvider createInstance(SerializationConfig config,
                                                 SerializerFactory jsf)

      Method that sub-classes need to implement: used to create a non-blueprint instances from the blueprint. This is needed to retain state during serialization.

    - #### copy

          public DefaultSerializerProvider copy()

      Method needed to ensure that `ObjectMapper.copy()` will work properly; specifically, that caches are cleared, but settings will otherwise remain identical; and that no sharing of state occurs.
      Since:
        2.5

    - #### serializerInstance

          public JsonSerializer<java.lang.Object> serializerInstance(Annotated annotated,
                                                            java.lang.Object serDef)
                                                              throws JsonMappingException

      Description copied from class: `SerializerProvider`
      Method that can be called to construct and configure serializer instance, either given a `Class` to instantiate (with default constructor), or an uninitialized serializer instance. Either way, serialize will be properly resolved (via `ResolvableSerializer`) and/or contextualized (via `ContextualSerializer`) as necessary.
      Specified by:
        `serializerInstance` in class `SerializerProvider`
      Parameters:
        `annotated` - Annotated entity that contained definition
        `serDef` - Serializer definition: either an instance or class
      Throws:
        `JsonMappingException`

    - #### findObjectId

          public WritableObjectId findObjectId(java.lang.Object forPojo,
                                      com.fasterxml.jackson.annotation.ObjectIdGenerator<?> generatorType)

      Description copied from class: `SerializerProvider`
      Method called to find the Object Id for given POJO, if one has been generated. Will always return a non-null Object; contents vary depending on whether an Object Id already exists or not.
      Specified by:
        `findObjectId` in class `SerializerProvider`

    - #### _createObjectIdMap

          protected java.util.Map<java.lang.Object,WritableObjectId> _createObjectIdMap()

      Overridable helper method used for creating `Map` used for storing mappings from serializable objects to their Object Ids.
      Since:
        2.3

    - #### hasSerializerFor

          public boolean hasSerializerFor(java.lang.Class<?> cls,
                                 java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> cause)

      Method that can be called to see if this serializer provider can find a serializer for an instance of given class.

      Note that no Exceptions are thrown, including unchecked ones: implementations are to swallow exceptions if necessary.

    - #### getGenerator

          public com.fasterxml.jackson.core.JsonGenerator getGenerator()

      Accessor for the `JsonGenerator` currently in use for serializing content. Null for blueprint instances; non-null for actual active provider instances.
      Overrides:
        `getGenerator` in class `SerializerProvider`
      Since:
        2.8

    - #### serializeValue

          public void serializeValue(com.fasterxml.jackson.core.JsonGenerator gen,
                            java.lang.Object value)
                              throws java.io.IOException

      The method to be called by `ObjectMapper` and `ObjectWriter` for serializing given value, using serializers that this provider has access to (via caching and/or creating new serializers as need be).
      Throws:
        `java.io.IOException`

    - #### serializeValue

          public void serializeValue(com.fasterxml.jackson.core.JsonGenerator gen,
                            java.lang.Object value,
                            JavaType rootType)
                              throws java.io.IOException

      The method to be called by `ObjectMapper` and `ObjectWriter` for serializing given value (assumed to be of specified root type, instead of runtime type of value), using serializers that this provider has access to (via caching and/or creating new serializers as need be),
      Parameters:
        `rootType` - Type to use for locating serializer to use, instead of actual runtime type. Must be actual type, or one of its super types
      Throws:
        `java.io.IOException`

    - #### serializeValue

          public void serializeValue(com.fasterxml.jackson.core.JsonGenerator gen,
                            java.lang.Object value,
                            JavaType rootType,
                            JsonSerializer<java.lang.Object> ser)
                              throws java.io.IOException

      The method to be called by `ObjectWriter` for serializing given value (assumed to be of specified root type, instead of runtime type of value), when it may know specific `JsonSerializer` to use.
      Parameters:
        `rootType` - Type to use for locating serializer to use, instead of actual runtime type, if no serializer is passed
        `ser` - Root Serializer to use, if not null
      Throws:
        `java.io.IOException`
      Since:
        2.1

    - #### serializePolymorphic

          public void serializePolymorphic(com.fasterxml.jackson.core.JsonGenerator gen,
                                  java.lang.Object value,
                                  JavaType rootType,
                                  JsonSerializer<java.lang.Object> valueSer,
                                  TypeSerializer typeSer)
                                    throws java.io.IOException

      Alternate serialization call used for polymorphic types, when `TypeSerializer` is already known, but the actual serializer may or may not be.
      Throws:
        `java.io.IOException`
      Since:
        2.6

    - #### serializePolymorphic

          @Deprecated
          public void serializePolymorphic(com.fasterxml.jackson.core.JsonGenerator gen,
                                             java.lang.Object value,
                                             TypeSerializer typeSer)
                                    throws java.io.IOException

      Deprecated. since 2.6; remove from 2.7 or later
      Throws:
        `java.io.IOException`

    - #### _serializeNull

          protected void _serializeNull(com.fasterxml.jackson.core.JsonGenerator gen)
                                 throws java.io.IOException

      Helper method called when root value to serialize is null
      Throws:
        `java.io.IOException`
      Since:
        2.3

    - #### cachedSerializersCount

          public int cachedSerializersCount()

      Method that can be used to determine how many serializers this provider is caching currently (if it does caching: default implementation does) Exact count depends on what kind of serializers get cached; default implementation caches all serializers, including ones that are eagerly constructed (for optimal access speed)

      The main use case for this method is to allow conditional flushing of serializer cache, if certain number of entries is reached.

    - #### flushCachedSerializers

          public void flushCachedSerializers()

      Method that will drop all serializers currently cached by this provider. This can be used to remove memory usage (in case some serializers are only used once or so), or to force re-construction of serializers after configuration changes for mapper than owns the provider.

    - #### acceptJsonFormatVisitor

          public void acceptJsonFormatVisitor(JavaType javaType,
                                     JsonFormatVisitorWrapper visitor)
                                       throws JsonMappingException

      The method to be called by `ObjectMapper` and `ObjectWriter` to to expose the format of the given to to the given visitor
      Parameters:
        `javaType` - The type for which to generate format
        `visitor` - the visitor to accept the format
      Throws:
        `JsonMappingException`

    - #### generateJsonSchema

          @Deprecated
          public JsonSchema generateJsonSchema(java.lang.Class<?> type)
                                        throws JsonMappingException

      Deprecated. Should not be used any more
      The method to be called by `ObjectMapper` to generate JSON schema for given type.
      Parameters:
        `type` - The type for which to generate schema
      Throws:
        `JsonMappingException`