Package org.codehaus.jackson.map.ser
Class BeanSerializerModifier
- java.lang.Object
-
- org.codehaus.jackson.map.ser.BeanSerializerModifier
-
public abstract class BeanSerializerModifier extends Object
Abstract class that defines API for objects that can be registered (forBeanSerializerFactory
to participate in constructingBeanSerializer
instances. This is typically done by modules that want alter some aspects of serialization process; and is preferable to sub-classing ofBeanSerializerFactory
.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(org.codehaus.jackson.map.SerializationConfig, org.codehaus.jackson.map.introspect.BasicBeanDescription, java.util.List<org.codehaus.jackson.map.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(org.codehaus.jackson.map.SerializationConfig, org.codehaus.jackson.map.introspect.BasicBeanDescription, java.util.List<org.codehaus.jackson.map.ser.BeanPropertyWriter>)
is called to allow modifiers to alter ordering. - After all bean properties and related information is accumulated,
updateBuilder(org.codehaus.jackson.map.SerializationConfig, org.codehaus.jackson.map.introspect.BasicBeanDescription, org.codehaus.jackson.map.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(org.codehaus.jackson.map.SerializationConfig, org.codehaus.jackson.map.introspect.BasicBeanDescription, org.codehaus.jackson.map.JsonSerializer<?>)
, for possible modification or replacement (by anyJsonSerializer
instance)
Default method implementations are "no-op"s, meaning that methods are implemented but have no effect.
- Since:
- 1.7
- After factory has collected tentative set of properties (instances of
-
-
Constructor Summary
Constructors Constructor Description BeanSerializerModifier()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<BeanPropertyWriter>
changeProperties(SerializationConfig config, BasicBeanDescription beanDesc, List<BeanPropertyWriter> beanProperties)
Method called byBeanSerializerFactory
with tentative set of discovered properties.JsonSerializer<?>
modifySerializer(SerializationConfig config, BasicBeanDescription beanDesc, JsonSerializer<?> serializer)
Method called byBeanSerializerFactory
after constructing default bean serializer instance with properties collected and ordered earlier.List<BeanPropertyWriter>
orderProperties(SerializationConfig config, BasicBeanDescription 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).BeanSerializerBuilder
updateBuilder(SerializationConfig config, BasicBeanDescription beanDesc, BeanSerializerBuilder builder)
Method called byBeanSerializerFactory
after collecting all information regarding POJO to serialize and updating builder with it, but before constructing serializer.
-
-
-
Method Detail
-
changeProperties
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BasicBeanDescription 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, BasicBeanDescription 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, BasicBeanDescription 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 JsonSerializer<?> modifySerializer(SerializationConfig config, BasicBeanDescription beanDesc, JsonSerializer<?> 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.
-
-