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) protected ValueSerializer<?>_findSerializer(SerializationConfig config, JavaType type) 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 CANNOT beObject, as a sanity check).addSerializers(List<ValueSerializer<?>> sers) findArraySerializer(SerializationConfig config, ArrayType type, BeanDescription.Supplier beanDescRef, 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.Supplier beanDescRef, 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.Supplier beanDescRef, JsonFormat.Value formatOverrides, TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer) Method called by serialization framework first time a serializer is needed for specifiedCollectiontype.findEnumSerializer(SerializationConfig config, JavaType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides) Method called by serialization framework first time a serializer is needed for givenEnumtype.findMapLikeSerializer(SerializationConfig config, MapLikeType type, BeanDescription.Supplier beanDescRef, 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.Supplier beanDescRef, JsonFormat.Value formatOverrides, ValueSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, ValueSerializer<Object> elementValueSerializer) Method called by serialization framework first time a serializer is needed for specifiedMaptype.findReferenceSerializer(SerializationConfig config, ReferenceType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides, TypeSerializer contentTypeSerializer, ValueSerializer<Object> contentValueSerializer) Method called by serialization framework first time a serializer is needed for givenReferenceTypefindSerializer(SerializationConfig config, JavaType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides) Fallback ethod called by serialization framework first time a serializer is needed for given type, which is not of any more specific type (like enum, tree node, reference or container type) for which other methods are called).findTreeNodeSerializer(SerializationConfig config, JavaType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides) Methods inherited from class tools.jackson.databind.ser.Serializers.Base
calculateEffectiveFormatMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface tools.jackson.databind.ser.Serializers
findExplicitPOJOSerializer
-
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 CANNOT 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.Supplier beanDescRef, JsonFormat.Value formatOverrides) Description copied from interface:SerializersFallback ethod called by serialization framework first time a serializer is needed for given type, which is not of any more specific type (like enum, tree node, reference or container type) for which other methods are called).Basically called for types for which none of other callbacks are called.
- Specified by:
findSerializerin interfaceSerializers- Parameters:
config- Serialization configuration in usetype- Fully resolved type of instances to serializebeanDescRef- Accessor to 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
-
findEnumSerializer
public ValueSerializer<?> findEnumSerializer(SerializationConfig config, JavaType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides) Description copied from interface:SerializersMethod called by serialization framework first time a serializer is needed for givenEnumtype.- Specified by:
findEnumSerializerin interfaceSerializersformatOverrides- (nullable) Optional format overrides (usually from property definition), to change definitions thatbeanDescRefmay have (and which are NOT included). Usually combined callingSerializers.Base#calculateEffectiveFormat.
-
findTreeNodeSerializer
public ValueSerializer<?> findTreeNodeSerializer(SerializationConfig config, JavaType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides) Description copied from interface:SerializersMethod called by serialization framework first time a serializer is needed for givenTreeNode(usuallyJsonNode) type.- Specified by:
findTreeNodeSerializerin interfaceSerializersformatOverrides- (nullable) Optional format overrides (usually from property definition), to change definitions thatbeanDescRefmay have (and which are NOT included). Usually combined callingSerializers.Base#calculateEffectiveFormat.
-
findArraySerializer
public ValueSerializer<?> findArraySerializer(SerializationConfig config, ArrayType type, BeanDescription.Supplier beanDescRef, 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 interfaceSerializersformatOverrides- (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.Supplier beanDescRef, 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 interfaceSerializersformatOverrides- (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.Supplier beanDescRef, 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 interfaceSerializersformatOverrides- (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.Supplier beanDescRef, 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 interfaceSerializersformatOverrides- (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.Supplier beanDescRef, 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 interfaceSerializersformatOverrides- (nullable) Optional format overrides (usually from property definition), to change definitions thatbeanDescmay have (and which are NOT included). Usually combined callingSerializers.Base#calculateEffectiveFormat.
-
findReferenceSerializer
public ValueSerializer<?> findReferenceSerializer(SerializationConfig config, ReferenceType type, BeanDescription.Supplier beanDescRef, JsonFormat.Value formatOverrides, TypeSerializer contentTypeSerializer, ValueSerializer<Object> contentValueSerializer) Description copied from interface:SerializersMethod called by serialization framework first time a serializer is needed for givenReferenceType- Specified by:
findReferenceSerializerin interfaceSerializersformatOverrides- (nullable) Optional format overrides (usually from property definition), to change definitions thatbeanDescmay have (and which are NOT included). Usually combined callingSerializers.Base#calculateEffectiveFormat.
-
_findSerializer
-
_findInterfaceMapping
-
_addSerializer
-