java.lang.Object
tools.jackson.databind.ser.Serializers.Base
tools.jackson.databind.module.SimpleSerializers
- All Implemented Interfaces:
Serializable,Serializers
Simple implementation
Serializers which allows registration of
serializers based on raw (type erased class).
It can work well for basic bean and scalar type serializers, but is not
a good fit for handling generic types (like Maps and Collections).
Type registrations are assumed to be general; meaning that registration of serializer
for a super type will also be used for handling subtypes, unless an exact match
is found first. As an example, handler for CharSequence would also be used
serializing StringBuilder instances, unless a direct mapping was found.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface tools.jackson.databind.ser.Serializers
Serializers.Base -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected HashMap<ClassKey,ValueSerializer<?>> Class-based mappings that are used both for exact and sub-class matches.protected booleanFlag to help find "generic" enum serializer, if one has been registered.protected HashMap<ClassKey,ValueSerializer<?>> Interface-based matches. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void_addSerializer(Class<?> cls, ValueSerializer<?> ser) protected ValueSerializer<?>_findInterfaceMapping(Class<?> cls, ClassKey key) addSerializer(Class<? extends T> type, ValueSerializer<T> ser) addSerializer(ValueSerializer<?> ser) Method for adding given serializer for type thatValueSerializer.handledType()specifies (which MUST return a non-null class; and can NOT beObject, as a sanity check).addSerializers(List<ValueSerializer<?>> sers) findArraySerializer(SerializationConfig config, ArrayType type, BeanDescription beanDesc, JsonFormat.Value formatOverrides, TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer) Method called by serialization framework first time a serializer is needed for specified array type.findCollectionLikeSerializer(SerializationConfig config, CollectionLikeType type, BeanDescription beanDesc, JsonFormat.Value formatOverrides, TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer) Method called by serialization framework first time a serializer is needed for specified "Collection-like" type (type that acts likeCollection, but does not implement it).findCollectionSerializer(SerializationConfig config, CollectionType type, BeanDescription beanDesc, JsonFormat.Value formatOverrides, TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer) Method called by serialization framework first time a serializer is needed for specifiedCollectiontype.findMapLikeSerializer(SerializationConfig config, MapLikeType type, BeanDescription beanDesc, JsonFormat.Value formatOverrides, ValueSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer) Method called by serialization framework first time a serializer is needed for specified "Map-like" type (type that acts likeMap, but does not implement it).findMapSerializer(SerializationConfig config, MapType type, BeanDescription beanDesc, JsonFormat.Value formatOverrides, ValueSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer) Method called by serialization framework first time a serializer is needed for specifiedMaptype.findSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc, JsonFormat.Value formatOverrides) Method called by serialization framework first time a serializer is needed for specified type, which is not of a container or reference type (for which other methods are called).Methods inherited from class tools.jackson.databind.ser.Serializers.Base
calculateEffectiveFormat, findExplicitPOJOSerializer, findReferenceSerializer
-
Field Details
-
_classMappings
Class-based mappings that are used both for exact and sub-class matches. -
_interfaceMappings
Interface-based matches. -
_hasEnumSerializer
protected boolean _hasEnumSerializerFlag to help find "generic" enum serializer, if one has been registered.
-
-
Constructor Details
-
SimpleSerializers
public SimpleSerializers() -
SimpleSerializers
-
-
Method Details
-
addSerializer
Method for adding given serializer for type thatValueSerializer.handledType()specifies (which MUST return a non-null class; and can NOT beObject, as a sanity check). For serializers that do not declare handled type, use the variant that takes two arguments.- Parameters:
ser-
-
addSerializer
-
addSerializers
-
findSerializer
public ValueSerializer<?> findSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc, JsonFormat.Value formatOverrides) Description copied from interface:SerializersMethod called by serialization framework first time a serializer is needed for specified type, which is not of a container or reference type (for which other methods are called).- Specified by:
findSerializerin interfaceSerializers- Overrides:
findSerializerin classSerializers.Base- Parameters:
config- Serialization configuration in usetype- Fully resolved type of instances to serializebeanDesc- Additional information about typeformatOverrides- (nullable) Optional format overrides (usually from property definition), to change definitions thatbeanDescmay have (and which are NOT included). Usually combined callingSerializers.Base#calculateEffectiveFormat.- Returns:
- Configured serializer to use for the type; or null if implementation does not recognize or support type
-
findArraySerializer
public ValueSerializer<?> findArraySerializer(SerializationConfig config, ArrayType type, BeanDescription beanDesc, JsonFormat.Value formatOverrides, TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer) Description copied from interface:SerializersMethod called by serialization framework first time a serializer is needed for specified array type. Implementation should return a serializer instance if it supports specified type; or null if it does not.- Specified by:
findArraySerializerin interfaceSerializers- Overrides:
findArraySerializerin classSerializers.BaseformatOverrides- (nullable) Optional format overrides (usually from property definition), to change definitions thatbeanDescmay have (and which are NOT included). Usually combined callingSerializers.Base#calculateEffectiveFormat.
-
findCollectionSerializer
public ValueSerializer<?> findCollectionSerializer(SerializationConfig config, CollectionType type, BeanDescription beanDesc, JsonFormat.Value formatOverrides, TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer) Description copied from interface:SerializersMethod called by serialization framework first time a serializer is needed for specifiedCollectiontype. Implementation should return a serializer instance if it supports specified type; or null if it does not.- Specified by:
findCollectionSerializerin interfaceSerializers- Overrides:
findCollectionSerializerin classSerializers.BaseformatOverrides- (nullable) Optional format overrides (usually from property definition), to change definitions thatbeanDescmay have (and which are NOT included). Usually combined callingSerializers.Base#calculateEffectiveFormat.
-
findCollectionLikeSerializer
public ValueSerializer<?> findCollectionLikeSerializer(SerializationConfig config, CollectionLikeType type, BeanDescription beanDesc, JsonFormat.Value formatOverrides, TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer) Description copied from interface:SerializersMethod called by serialization framework first time a serializer is needed for specified "Collection-like" type (type that acts likeCollection, but does not implement it). Implementation should return a serializer instance if it supports specified type; or null if it does not.- Specified by:
findCollectionLikeSerializerin interfaceSerializers- Overrides:
findCollectionLikeSerializerin classSerializers.BaseformatOverrides- (nullable) Optional format overrides (usually from property definition), to change definitions thatbeanDescmay have (and which are NOT included). Usually combined callingSerializers.Base#calculateEffectiveFormat.
-
findMapSerializer
public ValueSerializer<?> findMapSerializer(SerializationConfig config, MapType type, BeanDescription beanDesc, JsonFormat.Value formatOverrides, ValueSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer) Description copied from interface:SerializersMethod called by serialization framework first time a serializer is needed for specifiedMaptype. Implementation should return a serializer instance if it supports specified type; or null if it does not.- Specified by:
findMapSerializerin interfaceSerializers- Overrides:
findMapSerializerin classSerializers.BaseformatOverrides- (nullable) Optional format overrides (usually from property definition), to change definitions thatbeanDescmay have (and which are NOT included). Usually combined callingSerializers.Base#calculateEffectiveFormat.
-
findMapLikeSerializer
public ValueSerializer<?> findMapLikeSerializer(SerializationConfig config, MapLikeType type, BeanDescription beanDesc, JsonFormat.Value formatOverrides, ValueSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer) Description copied from interface:SerializersMethod called by serialization framework first time a serializer is needed for specified "Map-like" type (type that acts likeMap, but does not implement it). Implementation should return a serializer instance if it supports specified type; or null if it does not.- Specified by:
findMapLikeSerializerin interfaceSerializers- Overrides:
findMapLikeSerializerin classSerializers.BaseformatOverrides- (nullable) Optional format overrides (usually from property definition), to change definitions thatbeanDescmay have (and which are NOT included). Usually combined callingSerializers.Base#calculateEffectiveFormat.
-
_findInterfaceMapping
-
_addSerializer
-