BeanSerializer (Jackson JSON Processor)
Date: 2013-07-14

org.codehaus.jackson.map.ser

## Class BeanSerializer

- java.lang.Object
- - org.codehaus.jackson.map.JsonSerializer<T>
  - - org.codehaus.jackson.map.ser.std.SerializerBase<Object>
    - - org.codehaus.jackson.map.ser.std.BeanSerializerBase
      - - org.codehaus.jackson.map.ser.BeanSerializer

- All Implemented Interfaces:
    ResolvableSerializer, SchemaAware

      public class BeanSerializer
      extends BeanSerializerBase

  Serializer class that can serialize arbitrary bean objects

  Implementation note: we will post-process resulting serializer, to figure out actual serializers for final types. This must be done from `BeanSerializerBase.resolve(org.codehaus.jackson.map.SerializerProvider)` method, and NOT from constructor; otherwise we could end up with an infinite loop.

  Since 1.7 instances are immutable; this is achieved by using a separate builder during construction process.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.codehaus.jackson.map.JsonSerializer

      `JsonSerializer.None`

  - ### Field Summary

    - ### Fields inherited from class org.codehaus.jackson.map.ser.std.BeanSerializerBase

      `_anyGetterWriter, _filteredProps, _propertyFilterId, _props, NO_PROPS`

    - ### Fields inherited from class org.codehaus.jackson.map.ser.std.SerializerBase

      `_handledType`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `BeanSerializer(BeanSerializer src)` Copy-constructor that is useful for sub-classes that just want to copy all super-class properties without modifications.
    `protected` | `BeanSerializer(BeanSerializerBase src)` Alternate copy constructor that can be used to construct standard `BeanSerializer` passing an instance of "compatible enough" source serializer.
    `` | `BeanSerializer(Class<?> rawType, BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties, AnyGetterWriter anyGetterWriter, Object filterId)`
    `` | `BeanSerializer(JavaType type, BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties, AnyGetterWriter anyGetterWriter, Object filterId)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static BeanSerializer` | `createDummy(Class<?> forType)` Method for constructing dummy bean deserializer; one that never outputs any properties
    `void` | `serialize(Object bean, JsonGenerator jgen, SerializerProvider provider)` Main serialization method that will delegate actual output to configured `BeanPropertyWriter` instances.
    `String` | `toString()`
    `JsonSerializer<Object>` | `unwrappingSerializer()` Method that will return serializer instance that produces "unwrapped" serialization, if applicable for type being serialized (which is the case for some serializers that produce JSON Objects as output).

    - ### Methods inherited from class org.codehaus.jackson.map.ser.std.BeanSerializerBase

      `findFilter, getSchema, resolve, serializeFields, serializeFieldsFiltered, serializeWithType`

    - ### Methods inherited from class org.codehaus.jackson.map.ser.std.SerializerBase

      `createObjectNode, createSchemaNode, createSchemaNode, handledType, isDefaultSerializer, wrapAndThrow, wrapAndThrow, wrapAndThrow, wrapAndThrow`

    - ### Methods inherited from class org.codehaus.jackson.map.JsonSerializer

      `isUnwrappingSerializer`

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

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

- - ### Constructor Detail

    - #### BeanSerializer

          public BeanSerializer(JavaType type,
                        BeanPropertyWriter[] properties,
                        BeanPropertyWriter[] filteredProperties,
                        AnyGetterWriter anyGetterWriter,
                        Object filterId)

      Parameters:
        `type` - Nominal type of values handled by this serializer
        `properties` - Property writers used for actual serialization

    - #### BeanSerializer

          public BeanSerializer(Class<?> rawType,
                        BeanPropertyWriter[] properties,
                        BeanPropertyWriter[] filteredProperties,
                        AnyGetterWriter anyGetterWriter,
                        Object filterId)

    - #### BeanSerializer

          protected BeanSerializer(BeanSerializer src)

      Copy-constructor that is useful for sub-classes that just want to copy all super-class properties without modifications.
      Since:
        1.7

    - #### BeanSerializer

          protected BeanSerializer(BeanSerializerBase src)

      Alternate copy constructor that can be used to construct standard `BeanSerializer` passing an instance of "compatible enough" source serializer.
      Since:
        1.9

  - ### Method Detail

    - #### createDummy

          public static BeanSerializer createDummy(Class<?> forType)

      Method for constructing dummy bean deserializer; one that never outputs any properties

    - #### unwrappingSerializer

          public JsonSerializer<Object> unwrappingSerializer()

      Description copied from class: `JsonSerializer`
      Method that will return serializer instance that produces "unwrapped" serialization, if applicable for type being serialized (which is the case for some serializers that produce JSON Objects as output). If no unwrapped serializer can be constructed, will simply return serializer as-is.

      Default implementation just returns serializer as-is, indicating that no unwrapped variant exists

      Overrides:
        `unwrappingSerializer` in class `JsonSerializer<Object>`

    - #### serialize

          public final void serialize(Object bean,
                       JsonGenerator jgen,
                       SerializerProvider provider)
                               throws IOException,
                                      JsonGenerationException

      Main serialization method that will delegate actual output to configured `BeanPropertyWriter` instances.
      Specified by:
        `serialize` in class `BeanSerializerBase`
      Parameters:
        `bean` - Value to serialize; can not be null.
        `jgen` - Generator used to output resulting Json content
        `provider` - Provider that can be used to get serializers for serializing Objects value contains, if any.
      Throws:
        `IOException`
        `JsonGenerationException`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`