Class SerializationContexts

java.lang.Object
tools.jackson.databind.cfg.SerializationContexts
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
SerializationContexts.DefaultImpl

public abstract class SerializationContexts extends Object implements Serializable
Factory/builder class that replaces Jackson 2.x concept of "blueprint" instance of SerializationContext. It will be constructed and configured during ObjectMapper building phase, and will be called once per writeValue call to construct actual stateful SerializationContext to use during serialization.

Note that since this object has to be serializable (to allow JDK serialization of mapper instances), SerializationContext need not be serializable any more.

Since:
3.0
See Also:
  • Field Details

    • _streamFactory

      protected final transient TokenStreamFactory _streamFactory
      Low-level TokenStreamFactory that may be used for constructing embedded generators.
    • _serializerFactory

      protected final transient SerializerFactory _serializerFactory
      Factory responsible for constructing standard serializers.
    • _cache

      protected final transient SerializerCache _cache
      Cache for doing type-to-value-serializer lookups.
  • Constructor Details

  • Method Details

    • forMapper

      public SerializationContexts forMapper(Object mapper, SerializationConfig config, TokenStreamFactory tsf, SerializerFactory serializerFactory)
      Mutant factory method called when instance is actually created for use by mapper (as opposed to coming into existence during building, module registration). Necessary usually to initialize non-configuration state, such as caching.
    • forMapper

      protected abstract SerializationContexts forMapper(Object mapper, TokenStreamFactory tsf, SerializerFactory serializerFactory, SerializerCache cache)
    • createContext

      public abstract SerializationContextExt createContext(SerializationConfig config, GeneratorSettings genSettings)
      Factory method for constructing context object for individual writeValue() calls.
    • 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.