Top Description Inners Fields Constructors Methods
com.fasterxml.jackson.databind.ser.impl

public abstract Class PropertySerializerMap

extends Object
Class Inheritance
Known Direct Subclasses
com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.Empty, com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.Single, com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.Double, com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.Multi
Imports
java.util.Arrays, com.fasterxml.jackson.databind.BeanProperty, .JavaType, .JsonMappingException, .JsonSerializer, .SerializerProvider

Helper container used for resolving serializers for dynamic (possibly but not necessarily polymorphic) properties: properties whose type is not forced to use dynamic (declared) type and that are not final. If so, serializer to use can only be established once actual value type is known. Since this happens a lot unless static typing is forced (or types are final) this implementation is optimized for efficiency. Instances are immutable; new instances are created with factory methods: this is important to ensure correct multi-threaded access.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
PropertySerializerMap.Empty

Bogus instance that contains no serializers; used as the default map with new serializers.

private static class
public static class
PropertySerializerMap.SerializerAndMapResult

Value class used for returning tuple that has both serializer that was retrieved and new map instance

private static class
PropertySerializerMap.Single

Map that contains a single serializer; although seemingly silly this is probably the most commonly used variant because many theoretically dynamic or polymorphic types just have single actual type.

private static class
PropertySerializerMap.TypeAndSerializer

Trivial container for bundling type + serializer entries.

Field Summary

Modifier and TypeField and Description
protected final boolean
_resetWhenFull

Configuration setting that determines what happens when maximum size (currently 8) is reached: if true, will "start from beginning"; if false, will simply stop adding new entries.

Constructor Summary

AccessConstructor and Description
protected
PropertySerializerMap(boolean resetWhenFull)

protected

Method Summary

Modifier and TypeMethod and Description
public final PropertySerializerMap.SerializerAndMapResult
addSerializer(Class<?> type, JsonSerializer<Object> serializer)

Method that can be used to 'register' a serializer that caller has resolved without help of this map.

public final PropertySerializerMap.SerializerAndMapResult
public static PropertySerializerMap
public static PropertySerializerMap
public final PropertySerializerMap.SerializerAndMapResult
findAndAddKeySerializer(Class<?> type, SerializerProvider provider, BeanProperty property)

Method called if initial lookup fails, when looking for a key serializer (possible attached indirectly to a property) Will both find serializer and construct new map instance if warranted, and return both.

public final PropertySerializerMap.SerializerAndMapResult
findAndAddPrimarySerializer(Class<?> type, SerializerProvider provider, BeanProperty property)

Method called if initial lookup fails, when looking for a primary serializer (one that is directly attached to a property).

public final PropertySerializerMap.SerializerAndMapResult
public final PropertySerializerMap.SerializerAndMapResult
findAndAddRootValueSerializer(Class<?> type, SerializerProvider provider)

Method called if initial lookup fails, when looking for a root value serializer: one that is not directly attached to a property, but needs to have com.fasterxml.jackson.databind.jsontype.TypeSerializer wrapped around it.

public final PropertySerializerMap.SerializerAndMapResult
public final PropertySerializerMap.SerializerAndMapResult
findAndAddSecondarySerializer(Class<?> type, SerializerProvider provider, BeanProperty property)

Method called if initial lookup fails, when looking for a non-primary serializer (one that is not directly attached to a property).

public final PropertySerializerMap.SerializerAndMapResult
public abstract PropertySerializerMap
newWith(Class<?> type, JsonSerializer<Object> serializer)

public abstract JsonSerializer<Object>
serializerFor(Class<?> type)

Main lookup method.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_resetWhenFullback to summary
protected final boolean _resetWhenFull

Configuration setting that determines what happens when maximum size (currently 8) is reached: if true, will "start from beginning"; if false, will simply stop adding new entries.

Since
2.5

Constructor Detail

PropertySerializerMapback to summary
protected PropertySerializerMap(boolean resetWhenFull)
Since
2.5
PropertySerializerMapback to summary
protected PropertySerializerMap(PropertySerializerMap base)

Method Detail

addSerializerback to summary
public final PropertySerializerMap.SerializerAndMapResult addSerializer(Class<?> type, JsonSerializer<Object> serializer)

Method that can be used to 'register' a serializer that caller has resolved without help of this map.

Since
2.5
addSerializerback to summary
public final PropertySerializerMap.SerializerAndMapResult addSerializer(JavaType type, JsonSerializer<Object> serializer)
Since
2.5
emptyForPropertiesback to summary
public static PropertySerializerMap emptyForProperties()
Since
2.5
emptyForRootValuesback to summary
public static PropertySerializerMap emptyForRootValues()
Since
2.5
findAndAddKeySerializerback to summary
public final PropertySerializerMap.SerializerAndMapResult findAndAddKeySerializer(Class<?> type, SerializerProvider provider, BeanProperty property) throws JsonMappingException

Method called if initial lookup fails, when looking for a key serializer (possible attached indirectly to a property) Will both find serializer and construct new map instance if warranted, and return both.

Since
2.7
findAndAddPrimarySerializerback to summary
public final PropertySerializerMap.SerializerAndMapResult findAndAddPrimarySerializer(Class<?> type, SerializerProvider provider, BeanProperty property) throws JsonMappingException

Method called if initial lookup fails, when looking for a primary serializer (one that is directly attached to a property). Will both find serializer and construct new map instance if warranted, and return both.

Since
2.3
findAndAddPrimarySerializerback to summary
public final PropertySerializerMap.SerializerAndMapResult findAndAddPrimarySerializer(JavaType type, SerializerProvider provider, BeanProperty property) throws JsonMappingException
findAndAddRootValueSerializerback to summary
public final PropertySerializerMap.SerializerAndMapResult findAndAddRootValueSerializer(Class<?> type, SerializerProvider provider) throws JsonMappingException

Method called if initial lookup fails, when looking for a root value serializer: one that is not directly attached to a property, but needs to have com.fasterxml.jackson.databind.jsontype.TypeSerializer wrapped around it. Will both find the serializer and construct new map instance if warranted, and return both.

Since
2.5
findAndAddRootValueSerializerback to summary
public final PropertySerializerMap.SerializerAndMapResult findAndAddRootValueSerializer(JavaType type, SerializerProvider provider) throws JsonMappingException
Since
2.5
findAndAddSecondarySerializerback to summary
public final PropertySerializerMap.SerializerAndMapResult findAndAddSecondarySerializer(Class<?> type, SerializerProvider provider, BeanProperty property) throws JsonMappingException

Method called if initial lookup fails, when looking for a non-primary serializer (one that is not directly attached to a property). Will both find serializer and construct new map instance if warranted, and return both.

Since
2.3
findAndAddSecondarySerializerback to summary
public final PropertySerializerMap.SerializerAndMapResult findAndAddSecondarySerializer(JavaType type, SerializerProvider provider, BeanProperty property) throws JsonMappingException
newWithback to summary
public abstract PropertySerializerMap newWith(Class<?> type, JsonSerializer<Object> serializer)
serializerForback to summary
public abstract JsonSerializer<Object> serializerFor(Class<?> type)

Main lookup method. Takes a "raw" type since usage is always from place where parameterization is fixed such that there cannot be type-parametric variations.

com.fasterxml.jackson.databind.ser.impl back to summary

private final Class PropertySerializerMap.Double

extends PropertySerializerMap
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final JsonSerializer<Object>
private final JsonSerializer<Object>
private final Class<?>
private final Class<?>
Inherited from com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap:
_resetWhenFull

Constructor Summary

AccessConstructor and Description
public
Double(PropertySerializerMap base, Class<?> type1, JsonSerializer<Object> serializer1, Class<?> type2, JsonSerializer<Object> serializer2)

Method Summary

Modifier and TypeMethod and Description
public PropertySerializerMap
public JsonSerializer<Object>
Inherited from com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap:
addSerializeraddSerializeremptyForPropertiesemptyForRootValuesfindAndAddKeySerializerfindAndAddPrimarySerializerfindAndAddPrimarySerializerfindAndAddRootValueSerializerfindAndAddRootValueSerializerfindAndAddSecondarySerializerfindAndAddSecondarySerializer

Field Detail

_serializer1back to summary
private final JsonSerializer<Object> _serializer1
_serializer2back to summary
private final JsonSerializer<Object> _serializer2
_type1back to summary
private final Class<?> _type1
_type2back to summary
private final Class<?> _type2

Constructor Detail

Doubleback to summary
public Double(PropertySerializerMap base, Class<?> type1, JsonSerializer<Object> serializer1, Class<?> type2, JsonSerializer<Object> serializer2)

Method Detail

newWithback to summary
public PropertySerializerMap newWith(Class<?> type, JsonSerializer<Object> serializer)

Implements abstract com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.newWith.

Annotations
@Override
serializerForback to summary
public JsonSerializer<Object> serializerFor(Class<?> type)

Implements abstract com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.serializerFor.

Doc from com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.serializerFor.

Main lookup method. Takes a "raw" type since usage is always from place where parameterization is fixed such that there cannot be type-parametric variations.

Annotations
@Override
com.fasterxml.jackson.databind.ser.impl back to summary

private final Class PropertySerializerMap.Empty

extends PropertySerializerMap
Class Inheritance

Bogus instance that contains no serializers; used as the default map with new serializers.

Field Summary

Modifier and TypeField and Description
public static final PropertySerializerMap.Empty
public static final PropertySerializerMap.Empty
Inherited from com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap:
_resetWhenFull

Constructor Summary

AccessConstructor and Description
protected
Empty(boolean resetWhenFull)

Method Summary

Modifier and TypeMethod and Description
public PropertySerializerMap
public JsonSerializer<Object>
Inherited from com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap:
addSerializeraddSerializeremptyForPropertiesemptyForRootValuesfindAndAddKeySerializerfindAndAddPrimarySerializerfindAndAddPrimarySerializerfindAndAddRootValueSerializerfindAndAddRootValueSerializerfindAndAddSecondarySerializerfindAndAddSecondarySerializer

Field Detail

FOR_PROPERTIESback to summary
public static final PropertySerializerMap.Empty FOR_PROPERTIES
FOR_ROOT_VALUESback to summary
public static final PropertySerializerMap.Empty FOR_ROOT_VALUES

Constructor Detail

Emptyback to summary
protected Empty(boolean resetWhenFull)

Method Detail

newWithback to summary
public PropertySerializerMap newWith(Class<?> type, JsonSerializer<Object> serializer)

Implements abstract com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.newWith.

Annotations
@Override
serializerForback to summary
public JsonSerializer<Object> serializerFor(Class<?> type)

Implements abstract com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.serializerFor.

Doc from com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.serializerFor.

Main lookup method. Takes a "raw" type since usage is always from place where parameterization is fixed such that there cannot be type-parametric variations.

Annotations
@Override
com.fasterxml.jackson.databind.ser.impl back to summary

private final Class PropertySerializerMap.Multi

extends PropertySerializerMap
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final PropertySerializerMap.TypeAndSerializer[]
private static final int
MAX_ENTRIES

Let's limit number of serializers we actually cache; linear lookup won't scale too well beyond smallish number, and if we really want to support larger collections should use a hash map.

Inherited from com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap:
_resetWhenFull

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public PropertySerializerMap
public JsonSerializer<Object>
Inherited from com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap:
addSerializeraddSerializeremptyForPropertiesemptyForRootValuesfindAndAddKeySerializerfindAndAddPrimarySerializerfindAndAddPrimarySerializerfindAndAddRootValueSerializerfindAndAddRootValueSerializerfindAndAddSecondarySerializerfindAndAddSecondarySerializer

Field Detail

_entriesback to summary
private final PropertySerializerMap.TypeAndSerializer[] _entries
MAX_ENTRIESback to summary
private static final int MAX_ENTRIES

Let's limit number of serializers we actually cache; linear lookup won't scale too well beyond smallish number, and if we really want to support larger collections should use a hash map. But it seems unlikely this is a common use case so for now let's just stop building after hard-coded limit. 8 sounds like a reasonable stab for now.

Constructor Detail

Multiback to summary
public Multi(PropertySerializerMap base, PropertySerializerMap.TypeAndSerializer[] entries)

Method Detail

newWithback to summary
public PropertySerializerMap newWith(Class<?> type, JsonSerializer<Object> serializer)

Implements abstract com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.newWith.

Annotations
@Override
serializerForback to summary
public JsonSerializer<Object> serializerFor(Class<?> type)

Implements abstract com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.serializerFor.

Doc from com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.serializerFor.

Main lookup method. Takes a "raw" type since usage is always from place where parameterization is fixed such that there cannot be type-parametric variations.

Annotations
@Override
com.fasterxml.jackson.databind.ser.impl back to summary

public final Class PropertySerializerMap.SerializerAndMapResult

extends Object
Class Inheritance
  • java.lang.Object
  • com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.SerializerAndMapResult

Value class used for returning tuple that has both serializer that was retrieved and new map instance

Field Summary

Modifier and TypeField and Description
public final PropertySerializerMap
public final JsonSerializer<Object>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mapback to summary
public final PropertySerializerMap map
serializerback to summary
public final JsonSerializer<Object> serializer

Constructor Detail

SerializerAndMapResultback to summary
public SerializerAndMapResult(JsonSerializer<Object> serializer, PropertySerializerMap map)
com.fasterxml.jackson.databind.ser.impl back to summary

private final Class PropertySerializerMap.Single

extends PropertySerializerMap
Class Inheritance

Map that contains a single serializer; although seemingly silly this is probably the most commonly used variant because many theoretically dynamic or polymorphic types just have single actual type.

Field Summary

Modifier and TypeField and Description
private final JsonSerializer<Object>
private final Class<?>
Inherited from com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap:
_resetWhenFull

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public PropertySerializerMap
public JsonSerializer<Object>
Inherited from com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap:
addSerializeraddSerializeremptyForPropertiesemptyForRootValuesfindAndAddKeySerializerfindAndAddPrimarySerializerfindAndAddPrimarySerializerfindAndAddRootValueSerializerfindAndAddRootValueSerializerfindAndAddSecondarySerializerfindAndAddSecondarySerializer

Field Detail

_serializerback to summary
private final JsonSerializer<Object> _serializer
_typeback to summary
private final Class<?> _type

Constructor Detail

Singleback to summary
public Single(PropertySerializerMap base, Class<?> type, JsonSerializer<Object> serializer)

Method Detail

newWithback to summary
public PropertySerializerMap newWith(Class<?> type, JsonSerializer<Object> serializer)

Implements abstract com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.newWith.

Annotations
@Override
serializerForback to summary
public JsonSerializer<Object> serializerFor(Class<?> type)

Implements abstract com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.serializerFor.

Doc from com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.serializerFor.

Main lookup method. Takes a "raw" type since usage is always from place where parameterization is fixed such that there cannot be type-parametric variations.

Annotations
@Override
com.fasterxml.jackson.databind.ser.impl back to summary

private final Class PropertySerializerMap.TypeAndSerializer

extends Object
Class Inheritance
  • java.lang.Object
  • com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.TypeAndSerializer

Trivial container for bundling type + serializer entries.

Field Summary

Modifier and TypeField and Description
public final JsonSerializer<Object>
public final Class<?>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

serializerback to summary
public final JsonSerializer<Object> serializer
typeback to summary
public final Class<?> type

Constructor Detail

TypeAndSerializerback to summary
public TypeAndSerializer(Class<?> type, JsonSerializer<Object> serializer)