Class 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.

  • Constructor Details

    • 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 Details

    • 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