BeanSerializerModifier
Date: 2016-12-04

com.fasterxml.jackson.databind.ser

## Class BeanSerializerModifier

- java.lang.Object
- - com.fasterxml.jackson.databind.ser.BeanSerializerModifier

-     public abstract class BeanSerializerModifier
      extends java.lang.Object

  Abstract class that defines API for objects that can be registered (for `BeanSerializerFactory` to participate in constructing `BeanSerializer` instances. This is typically done by modules that want alter some aspects of serialization process; and is preferable to sub-classing of `BeanSerializerFactory`.

  Sequence in which callback methods are called is as follows:

  1. After factory has collected tentative set of properties (instances of `BeanPropertyWriter`) is sent for modification via `changeProperties(com.fasterxml.jackson.databind.SerializationConfig, com.fasterxml.jackson.databind.BeanDescription, java.util.List<com.fasterxml.jackson.databind.ser.BeanPropertyWriter>)`. Changes can include removal, addition and replacement of suggested properties.
  2. Resulting set of properties are ordered (sorted) by factory, as per configuration, and then `orderProperties(com.fasterxml.jackson.databind.SerializationConfig, com.fasterxml.jackson.databind.BeanDescription, java.util.List<com.fasterxml.jackson.databind.ser.BeanPropertyWriter>)` is called to allow modifiers to alter ordering.
  3. After all bean properties and related information is accumulated, `updateBuilder(com.fasterxml.jackson.databind.SerializationConfig, com.fasterxml.jackson.databind.BeanDescription, com.fasterxml.jackson.databind.ser.BeanSerializerBuilder)` is called with builder, to allow builder state to be modified (including possibly replacing builder itself if necessary)
  4. Once all bean information has been determined, factory creates default `BeanSerializer` instance and passes it to modifiers using `modifySerializer(com.fasterxml.jackson.databind.SerializationConfig, com.fasterxml.jackson.databind.BeanDescription, com.fasterxml.jackson.databind.JsonSerializer<?>)`, for possible modification or replacement (by any `JsonSerializer` instance)

  Default method implementations are "no-op"s, meaning that methods are implemented but have no effect.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BeanSerializerModifier()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.util.List<BeanPropertyWriter>` | `changeProperties(SerializationConfig config, BeanDescription beanDesc, java.util.List<BeanPropertyWriter> beanProperties)` Method called by `BeanSerializerFactory` with tentative set of discovered properties.
    `JsonSerializer<?>` | `modifyArraySerializer(SerializationConfig config, ArrayType valueType, BeanDescription beanDesc, JsonSerializer<?> serializer)` Method called by `DeserializerFactory` after it has constructed the standard serializer for given `ArrayType` to make it possible to either replace or augment this serializer with additional functionality.
    `JsonSerializer<?>` | `modifyCollectionLikeSerializer(SerializationConfig config, CollectionLikeType valueType, BeanDescription beanDesc, JsonSerializer<?> serializer)`
    `JsonSerializer<?>` | `modifyCollectionSerializer(SerializationConfig config, CollectionType valueType, BeanDescription beanDesc, JsonSerializer<?> serializer)`
    `JsonSerializer<?>` | `modifyEnumSerializer(SerializationConfig config, JavaType valueType, BeanDescription beanDesc, JsonSerializer<?> serializer)`
    `JsonSerializer<?>` | `modifyKeySerializer(SerializationConfig config, JavaType valueType, BeanDescription beanDesc, JsonSerializer<?> serializer)` Method called by `DeserializerFactory` after it has constructed the default key serializer to use for serializing `Map` keys of given type.
    `JsonSerializer<?>` | `modifyMapLikeSerializer(SerializationConfig config, MapLikeType valueType, BeanDescription beanDesc, JsonSerializer<?> serializer)`
    `JsonSerializer<?>` | `modifyMapSerializer(SerializationConfig config, MapType valueType, BeanDescription beanDesc, JsonSerializer<?> serializer)`
    `JsonSerializer<?>` | `modifySerializer(SerializationConfig config, BeanDescription beanDesc, JsonSerializer<?> serializer)` Method called by `BeanSerializerFactory` after constructing default bean serializer instance with properties collected and ordered earlier.
    `java.util.List<BeanPropertyWriter>` | `orderProperties(SerializationConfig config, BeanDescription beanDesc, java.util.List<BeanPropertyWriter> beanProperties)` Method called by `BeanSerializerFactory` with set of properties to serialize, in default ordering (based on defaults as well as possible type annotations).
    `BeanSerializerBuilder` | `updateBuilder(SerializationConfig config, BeanDescription beanDesc, BeanSerializerBuilder builder)` Method called by `BeanSerializerFactory` after collecting all information regarding POJO to serialize and updating builder with it, but before constructing serializer.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### BeanSerializerModifier

          public BeanSerializerModifier()

  - ### Method Detail

    - #### changeProperties

          public java.util.List<BeanPropertyWriter> changeProperties(SerializationConfig config,
                                                            BeanDescription beanDesc,
                                                            java.util.List<BeanPropertyWriter> beanProperties)

      Method called by `BeanSerializerFactory` with tentative set of discovered properties. Implementations can add, remove or replace any of passed properties. Properties `List` passed as argument is modifiable, and returned List must likewise be modifiable as it may be passed to multiple registered modifiers.

    - #### orderProperties

          public java.util.List<BeanPropertyWriter> orderProperties(SerializationConfig config,
                                                           BeanDescription beanDesc,
                                                           java.util.List<BeanPropertyWriter> beanProperties)

      Method called by `BeanSerializerFactory` 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. Properties `List` 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 beanDesc,
                                            BeanSerializerBuilder builder)

      Method called by `BeanSerializerFactory` 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,
                                           BeanDescription beanDesc,
                                           JsonSerializer<?> serializer)

      Method called by `BeanSerializerFactory` 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 type `BeanSerializer`, modifiers may return serializers of other types; and this is why implementations must check for type before casting.

      NOTE: since 2.2, gets called for serializer of those non-POJO types that do not go through any of more specific `modifyXxxSerializer` methods; mostly for JDK types like `Iterator` and such.

    - #### modifyArraySerializer

          public JsonSerializer<?> modifyArraySerializer(SerializationConfig config,
                                                ArrayType valueType,
                                                BeanDescription beanDesc,
                                                JsonSerializer<?> serializer)

      Method called by `DeserializerFactory` after it has constructed the standard serializer for given `ArrayType` to make it possible to either replace or augment this serializer with additional functionality.
      Parameters:
        `config` - Configuration in use
        `valueType` - Type of the value serializer is used for.
        `beanDesc` - Details of the type in question, to allow checking class annotations
        `serializer` - Default serializer that would be used.
      Returns:
        Serializer to use; either `serializer` that was passed in, or an instance method constructed.
      Since:
        2.2

    - #### modifyCollectionSerializer

          public JsonSerializer<?> modifyCollectionSerializer(SerializationConfig config,
                                                     CollectionType valueType,
                                                     BeanDescription beanDesc,
                                                     JsonSerializer<?> serializer)

      Since:
        2.2

    - #### modifyCollectionLikeSerializer

          public JsonSerializer<?> modifyCollectionLikeSerializer(SerializationConfig config,
                                                         CollectionLikeType valueType,
                                                         BeanDescription beanDesc,
                                                         JsonSerializer<?> serializer)

      Since:
        2.2

    - #### modifyMapSerializer

          public JsonSerializer<?> modifyMapSerializer(SerializationConfig config,
                                              MapType valueType,
                                              BeanDescription beanDesc,
                                              JsonSerializer<?> serializer)

      Since:
        2.2

    - #### modifyMapLikeSerializer

          public JsonSerializer<?> modifyMapLikeSerializer(SerializationConfig config,
                                                  MapLikeType valueType,
                                                  BeanDescription beanDesc,
                                                  JsonSerializer<?> serializer)

      Since:
        2.2

    - #### modifyEnumSerializer

          public JsonSerializer<?> modifyEnumSerializer(SerializationConfig config,
                                               JavaType valueType,
                                               BeanDescription beanDesc,
                                               JsonSerializer<?> serializer)

      Since:
        2.2

    - #### modifyKeySerializer

          public JsonSerializer<?> modifyKeySerializer(SerializationConfig config,
                                              JavaType valueType,
                                              BeanDescription beanDesc,
                                              JsonSerializer<?> serializer)

      Method called by `DeserializerFactory` after it has constructed the default key serializer to use for serializing `Map` keys of given type. This makes it possible to either replace or augment default serializer with additional functionality.
      Parameters:
        `config` - Configuration in use
        `valueType` - Type of keys the serializer is used for.
        `beanDesc` - Details of the type in question, to allow checking class annotations
        `serializer` - Default serializer that would be used.
      Returns:
        Serializer to use; either `serializer` that was passed in, or an instance method constructed.
      Since:
        2.2