Class SimpleSerializers
- java.lang.Object
-
- com.fasterxml.jackson.databind.ser.Serializers.Base
-
- com.fasterxml.jackson.databind.module.SimpleSerializers
-
- All Implemented Interfaces:
Serializers,java.io.Serializable
public class SimpleSerializers extends Serializers.Base implements java.io.Serializable
Simple implementationSerializerswhich 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 (likeMaps andCollections).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
CharSequencewould also be used serializingStringBuilderinstances, unless a direct mapping was found.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.fasterxml.jackson.databind.ser.Serializers
Serializers.Base
-
-
Constructor Summary
Constructors Constructor Description SimpleSerializers()SimpleSerializers(java.util.List<JsonSerializer<?>> sers)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSerializer(JsonSerializer<?> ser)Method for adding given serializer for type thatJsonSerializer.handledType()specifies (which MUST return a non-null class; and can NOT beObject, as a sanity check).<T> voidaddSerializer(java.lang.Class<? extends T> type, JsonSerializer<T> ser)voidaddSerializers(java.util.List<JsonSerializer<?>> sers)JsonSerializer<?>findArraySerializer(SerializationConfig config, ArrayType type, BeanDescription beanDesc, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.Object> elementValueSerializer)Method called by serialization framework first time a serializer is needed for specified array type.JsonSerializer<?>findCollectionLikeSerializer(SerializationConfig config, CollectionLikeType type, BeanDescription beanDesc, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.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).JsonSerializer<?>findCollectionSerializer(SerializationConfig config, CollectionType type, BeanDescription beanDesc, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.Object> elementValueSerializer)Method called by serialization framework first time a serializer is needed for specifiedCollectiontype.JsonSerializer<?>findMapLikeSerializer(SerializationConfig config, MapLikeType type, BeanDescription beanDesc, JsonSerializer<java.lang.Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.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).JsonSerializer<?>findMapSerializer(SerializationConfig config, MapType type, BeanDescription beanDesc, JsonSerializer<java.lang.Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.Object> elementValueSerializer)Method called by serialization framework first time a serializer is needed for specifiedMaptype.JsonSerializer<?>findSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc)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 com.fasterxml.jackson.databind.ser.Serializers.Base
findReferenceSerializer
-
-
-
-
Constructor Detail
-
SimpleSerializers
public SimpleSerializers()
-
SimpleSerializers
public SimpleSerializers(java.util.List<JsonSerializer<?>> sers)
- Since:
- 2.1
-
-
Method Detail
-
addSerializer
public void addSerializer(JsonSerializer<?> ser)
Method for adding given serializer for type thatJsonSerializer.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
public <T> void addSerializer(java.lang.Class<? extends T> type, JsonSerializer<T> ser)
-
addSerializers
public void addSerializers(java.util.List<JsonSerializer<?>> sers)
- Since:
- 2.1
-
findSerializer
public JsonSerializer<?> findSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc)
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 type- Returns:
- Configured serializer to use for the type; or null if implementation does not recognize or support type
-
findArraySerializer
public JsonSerializer<?> findArraySerializer(SerializationConfig config, ArrayType type, BeanDescription beanDesc, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.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.Base
-
findCollectionSerializer
public JsonSerializer<?> findCollectionSerializer(SerializationConfig config, CollectionType type, BeanDescription beanDesc, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.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.Base
-
findCollectionLikeSerializer
public JsonSerializer<?> findCollectionLikeSerializer(SerializationConfig config, CollectionLikeType type, BeanDescription beanDesc, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.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.Base
-
findMapSerializer
public JsonSerializer<?> findMapSerializer(SerializationConfig config, MapType type, BeanDescription beanDesc, JsonSerializer<java.lang.Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.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.Base
-
findMapLikeSerializer
public JsonSerializer<?> findMapLikeSerializer(SerializationConfig config, MapLikeType type, BeanDescription beanDesc, JsonSerializer<java.lang.Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<java.lang.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.Base
-
-