Class DefaultSerializerProvider

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
DefaultSerializerProvider.Impl, XmlSerializerProvider

public abstract class DefaultSerializerProvider extends SerializerProvider implements 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:
  • Method Details

    • 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

      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<Object> serializerInstance(Annotated annotated, 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
    • includeFilterInstance

      public Object includeFilterInstance(BeanPropertyDefinition forProperty, Class<?> filterClass)
      Description copied from class: SerializerProvider
      Method that can be called to construct and configure JsonInclude filter instance, given a Class to instantiate (with default constructor, by default).
      Specified by:
      includeFilterInstance in class SerializerProvider
      Parameters:
      forProperty - (optional) If filter is created for a property, that property; `null` if filter created via defaulting, global or per-type.
    • includeFilterSuppressNulls

      public boolean includeFilterSuppressNulls(Object filter) throws JsonMappingException
      Description copied from class: SerializerProvider
      Follow-up method that may be called after calling SerializerProvider.includeFilterInstance(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition, java.lang.Class<?>), to check handling of `null` values by the filter.
      Specified by:
      includeFilterSuppressNulls in class SerializerProvider
      Throws:
      JsonMappingException
    • withCaches

      public abstract DefaultSerializerProvider withCaches(CacheProvider cacheProvider)
      Fluent factory method used for constructing a new instance with cache instances provided by CacheProvider.
      Since:
      2.16
    • findObjectId

      public WritableObjectId findObjectId(Object forPojo, 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
    • hasSerializerFor

      public boolean hasSerializerFor(Class<?> cls, AtomicReference<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 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(JsonGenerator gen, Object value) throws 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:
      IOException
    • serializeValue

      public void serializeValue(JsonGenerator gen, Object value, JavaType rootType) throws 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:
      IOException
    • serializeValue

      public void serializeValue(JsonGenerator gen, Object value, JavaType rootType, JsonSerializer<Object> ser) throws 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:
      IOException
      Since:
      2.1
    • serializePolymorphic

      public void serializePolymorphic(JsonGenerator gen, Object value, JavaType rootType, JsonSerializer<Object> valueSer, TypeSerializer typeSer) throws IOException
      Alternate serialization call used for polymorphic types, when TypeSerializer is already known, but the actual serializer may or may not be.
      Throws:
      IOException
      Since:
      2.6
    • 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(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