java.lang.Object
tools.jackson.databind.ser.ValueSerializerModifier
- All Implemented Interfaces:
Serializable
Abstract class that defines API for objects that can be registered
(via
ObjectMapper
configuration process,
using MapperBuilder
)
to participate in constructing ValueSerializer
instances
(including but not limited to BeanSerializer
s).
This is typically done by modules that want alter some aspects of
the typical serialization process.
Sequence in which callback methods are called is as follows:
- After factory has collected tentative set of properties (instances of
BeanPropertyWriter
) is sent for modification viachangeProperties(tools.jackson.databind.SerializationConfig, tools.jackson.databind.BeanDescription.Supplier, java.util.List<tools.jackson.databind.ser.BeanPropertyWriter>)
. Changes can include removal, addition and replacement of suggested properties. - Resulting set of properties are ordered (sorted) by factory, as per
configuration, and then
orderProperties(tools.jackson.databind.SerializationConfig, tools.jackson.databind.BeanDescription.Supplier, java.util.List<tools.jackson.databind.ser.BeanPropertyWriter>)
is called to allow modifiers to alter ordering. - After all bean properties and related information is accumulated,
updateBuilder(tools.jackson.databind.SerializationConfig, tools.jackson.databind.BeanDescription.Supplier, tools.jackson.databind.ser.BeanSerializerBuilder)
is called with builder, to allow builder state to be modified (including possibly replacing builder itself if necessary) - Once all bean information has been determined,
factory creates default
BeanSerializer
instance and passes it to modifiers usingmodifySerializer(tools.jackson.databind.SerializationConfig, tools.jackson.databind.BeanDescription.Supplier, tools.jackson.databind.ValueSerializer<?>)
(or type-specic alternativemodifyXxxSerializer()
method), for possible modification or replacement (by anyValueSerializer
instance)
Default method implementations are "no-op"s, meaning that methods are implemented but have no effect.
NOTE: In Jackson 2.x was named BeanSerializerModifier
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchangeProperties
(SerializationConfig config, BeanDescription.Supplier beanDesc, List<BeanPropertyWriter> beanProperties) Method called byBeanSerializerFactory
with tentative set of discovered properties.modifyArraySerializer
(SerializationConfig config, ArrayType valueType, BeanDescription.Supplier beanDesc, ValueSerializer<?> serializer) Method called byDeserializerFactory
after it has constructed the standard serializer for givenArrayType
to make it possible to either replace or augment this serializer with additional functionality.modifyCollectionLikeSerializer
(SerializationConfig config, CollectionLikeType valueType, BeanDescription.Supplier beanDesc, ValueSerializer<?> serializer) modifyCollectionSerializer
(SerializationConfig config, CollectionType valueType, BeanDescription.Supplier beanDesc, ValueSerializer<?> serializer) modifyEnumSerializer
(SerializationConfig config, JavaType valueType, BeanDescription.Supplier beanDesc, ValueSerializer<?> serializer) modifyKeySerializer
(SerializationConfig config, JavaType valueType, BeanDescription.Supplier beanDesc, ValueSerializer<?> serializer) Method called byDeserializerFactory
after it has constructed the default key serializer to use for serializingMap
keys of given type.modifyMapLikeSerializer
(SerializationConfig config, MapLikeType valueType, BeanDescription.Supplier beanDesc, ValueSerializer<?> serializer) modifyMapSerializer
(SerializationConfig config, MapType valueType, BeanDescription.Supplier beanDesc, ValueSerializer<?> serializer) modifySerializer
(SerializationConfig config, BeanDescription.Supplier beanDesc, ValueSerializer<?> serializer) Method called byBeanSerializerFactory
after constructing default bean serializer instance with properties collected and ordered earlier.orderProperties
(SerializationConfig config, BeanDescription.Supplier beanDesc, List<BeanPropertyWriter> beanProperties) Method called byBeanSerializerFactory
with set of properties to serialize, in default ordering (based on defaults as well as possible type annotations).updateBuilder
(SerializationConfig config, BeanDescription.Supplier beanDesc, BeanSerializerBuilder builder) Method called byBeanSerializerFactory
after collecting all information regarding POJO to serialize and updating builder with it, but before constructing serializer.
-
Constructor Details
-
ValueSerializerModifier
public ValueSerializerModifier()
-
-
Method Details
-
changeProperties
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription.Supplier beanDesc, List<BeanPropertyWriter> beanProperties) Method called byBeanSerializerFactory
with tentative set of discovered properties. Implementations can add, remove or replace any of passed properties. PropertiesList
passed as argument is modifiable, and returned List must likewise be modifiable as it may be passed to multiple registered modifiers. -
orderProperties
public List<BeanPropertyWriter> orderProperties(SerializationConfig config, BeanDescription.Supplier beanDesc, List<BeanPropertyWriter> beanProperties) Method called byBeanSerializerFactory
with set of properties to serialize, in default ordering (based on defaults as well as possible type annotations). Implementations can change ordering any way they like. PropertiesList
passed as argument is modifiable, and returned List must likewise be modifiable as it may be passed to multiple registered modifiers. -
updateBuilder
public BeanSerializerBuilder updateBuilder(SerializationConfig config, BeanDescription.Supplier beanDesc, BeanSerializerBuilder builder) Method called byBeanSerializerFactory
after collecting all information regarding POJO to serialize and updating builder with it, but before constructing serializer. Implementations may choose to modify state of builder (to affect serializer being built), or even completely replace it (if they want to build different kind of serializer). Typically, however, passed-in builder is returned, possibly with some modifications. -
modifySerializer
public ValueSerializer<?> modifySerializer(SerializationConfig config, BeanDescription.Supplier beanDesc, ValueSerializer<?> serializer) Method called byBeanSerializerFactory
after constructing default bean serializer instance with properties collected and ordered earlier. Implementations can modify or replace given serializer and return serializer to use. Note that although initial serializer being passed is of typeBeanSerializer
, modifiers may return serializers of other types; and this is why implementations must check for type before casting.NOTE: this method gets called for serializer of those non-POJO types that do not go through any of more specific
modifyXxxSerializer
methods; mostly for JDK types likeIterator
and such. -
modifyArraySerializer
public ValueSerializer<?> modifyArraySerializer(SerializationConfig config, ArrayType valueType, BeanDescription.Supplier beanDesc, ValueSerializer<?> serializer) Method called byDeserializerFactory
after it has constructed the standard serializer for givenArrayType
to make it possible to either replace or augment this serializer with additional functionality.- Parameters:
config
- Configuration in usevalueType
- Type of the value serializer is used for.beanDesc
- Details of the type in question, to allow checking class annotationsserializer
- Default serializer that would be used.- Returns:
- Serializer to use; either
serializer
that was passed in, or an instance method constructed.
-
modifyCollectionSerializer
public ValueSerializer<?> modifyCollectionSerializer(SerializationConfig config, CollectionType valueType, BeanDescription.Supplier beanDesc, ValueSerializer<?> serializer) -
modifyCollectionLikeSerializer
public ValueSerializer<?> modifyCollectionLikeSerializer(SerializationConfig config, CollectionLikeType valueType, BeanDescription.Supplier beanDesc, ValueSerializer<?> serializer) -
modifyMapSerializer
public ValueSerializer<?> modifyMapSerializer(SerializationConfig config, MapType valueType, BeanDescription.Supplier beanDesc, ValueSerializer<?> serializer) -
modifyMapLikeSerializer
public ValueSerializer<?> modifyMapLikeSerializer(SerializationConfig config, MapLikeType valueType, BeanDescription.Supplier beanDesc, ValueSerializer<?> serializer) -
modifyEnumSerializer
public ValueSerializer<?> modifyEnumSerializer(SerializationConfig config, JavaType valueType, BeanDescription.Supplier beanDesc, ValueSerializer<?> serializer) -
modifyKeySerializer
public ValueSerializer<?> modifyKeySerializer(SerializationConfig config, JavaType valueType, BeanDescription.Supplier beanDesc, ValueSerializer<?> serializer) Method called byDeserializerFactory
after it has constructed the default key serializer to use for serializingMap
keys of given type. This makes it possible to either replace or augment default serializer with additional functionality.- Parameters:
config
- Configuration in usevalueType
- Type of keys the serializer is used for.beanDesc
- Details of the type in question, to allow checking class annotationsserializer
- Default serializer that would be used.- Returns:
- Serializer to use; either
serializer
that was passed in, or an instance method constructed.
-