com.fasterxml.jackson.databind.ser
Class DefaultSerializerProvider

java.lang.Object
  extended by com.fasterxml.jackson.databind.SerializerProvider
      extended by com.fasterxml.jackson.databind.ser.DefaultSerializerProvider
Direct Known Subclasses:
DefaultSerializerProvider.Impl

public abstract class DefaultSerializerProvider
extends SerializerProvider

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


Nested Class Summary
static class DefaultSerializerProvider.Impl
          Concrete implementation that defines factory method(s), defined as final.
 
Field Summary
protected  ArrayList<com.fasterxml.jackson.annotation.ObjectIdGenerator<?>> _objectIdGenerators
           
protected  IdentityHashMap<Object,WritableObjectId> _seenObjectIds
           
 
Fields inherited from class com.fasterxml.jackson.databind.SerializerProvider
_config, _dateFormat, _keySerializer, _knownSerializers, _nullKeySerializer, _nullValueSerializer, _rootNames, _serializationView, _serializerCache, _serializerFactory, _unknownTypeSerializer, CACHE_UNKNOWN_MAPPINGS, DEFAULT_NULL_KEY_SERIALIZER, DEFAULT_UNKNOWN_SERIALIZER, TYPE_OBJECT
 
Constructor Summary
protected DefaultSerializerProvider()
           
protected DefaultSerializerProvider(SerializerProvider src, SerializationConfig config, SerializerFactory f)
           
 
Method Summary
 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)
abstract  DefaultSerializerProvider createInstance(SerializationConfig config, SerializerFactory jsf)
          Overridable method, used to create a non-blueprint instances from the blueprint.
 WritableObjectId findObjectId(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(Class<?> type)
          The method to be called by ObjectMapper and ObjectWriter to generate JSON schema for given type.
 boolean hasSerializerFor(Class<?> cls)
          Method that can be called to see if this serializer provider can find a serializer for an instance of given class.
 com.fasterxml.jackson.annotation.ObjectIdGenerator<?> objectIdGeneratorInstance(Annotated annotated, ObjectIdInfo objectIdInfo)
           
 JsonSerializer<Object> serializerInstance(Annotated annotated, 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 jgen, 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 jgen, 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),
 
Methods inherited from class com.fasterxml.jackson.databind.SerializerProvider
_createAndCacheUntypedSerializer, _createAndCacheUntypedSerializer, _createUntypedSerializer, _dateFormat, _findExplicitUntypedSerializer, _handleContextual, _handleContextualResolvable, _handleResolvable, _reportIncompatibleRootType, canOverrideAccessModifiers, constructSpecializedType, constructType, defaultSerializeDateKey, defaultSerializeDateKey, defaultSerializeDateValue, defaultSerializeDateValue, defaultSerializeField, defaultSerializeNull, defaultSerializeValue, findKeySerializer, findNullKeySerializer, findNullValueSerializer, findTypedValueSerializer, findTypedValueSerializer, findValueSerializer, findValueSerializer, getAnnotationIntrospector, getConfig, getDefaultNullKeySerializer, getDefaultNullValueSerializer, getFilterProvider, getLocale, getSerializationView, getTimeZone, getTypeFactory, getUnknownTypeSerializer, isEnabled, isEnabled, setDefaultKeySerializer, setNullKeySerializer, setNullValueSerializer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_seenObjectIds

protected IdentityHashMap<Object,WritableObjectId> _seenObjectIds

_objectIdGenerators

protected ArrayList<com.fasterxml.jackson.annotation.ObjectIdGenerator<?>> _objectIdGenerators
Constructor Detail

DefaultSerializerProvider

protected DefaultSerializerProvider()

DefaultSerializerProvider

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

createInstance

public abstract DefaultSerializerProvider createInstance(SerializationConfig config,
                                                         SerializerFactory jsf)
Overridable method, used to create a non-blueprint instances from the blueprint. This is needed to retain state during serialization.


serializeValue

public void serializeValue(com.fasterxml.jackson.core.JsonGenerator jgen,
                           Object value)
                    throws IOException,
                           com.fasterxml.jackson.core.JsonGenerationException
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
com.fasterxml.jackson.core.JsonGenerationException

serializeValue

public void serializeValue(com.fasterxml.jackson.core.JsonGenerator jgen,
                           Object value,
                           JavaType rootType)
                    throws IOException,
                           com.fasterxml.jackson.core.JsonGenerationException
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
com.fasterxml.jackson.core.JsonGenerationException

generateJsonSchema

public JsonSchema generateJsonSchema(Class<?> type)
                              throws JsonMappingException
The method to be called by ObjectMapper and ObjectWriter to generate JSON schema for given type.

Parameters:
type - The type for which to generate schema
Throws:
JsonMappingException

hasSerializerFor

public boolean hasSerializerFor(Class<?> cls)
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.


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.


objectIdGeneratorInstance

public com.fasterxml.jackson.annotation.ObjectIdGenerator<?> objectIdGeneratorInstance(Annotated annotated,
                                                                                       ObjectIdInfo objectIdInfo)
                                                                                throws JsonMappingException
Specified by:
objectIdGeneratorInstance in class SerializerProvider
Throws:
JsonMappingException

findObjectId

public WritableObjectId findObjectId(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

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


Copyright © 2012 fasterxml.com. All Rights Reserved.