Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.ser;
  
  
Serializer class that can serialize Java objects that map to JSON Object output. Internally handling is mostly dealt with by a sequence of BeanPropertyWriters that will handle access value to serialize and call appropriate serializers to write out JSON.

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

 
 public class BeanSerializer
     extends BeanSerializerBase
 {
     /*
     /**********************************************************
     /* Life-cycle: constructors
     /**********************************************************
      */

    

Parameters:
builder Builder object that contains collected information that may be needed for serializer
properties Property writers used for actual serialization
 
     public BeanSerializer(JavaType typeBeanSerializerBuilder builder,
             BeanPropertyWriter[] propertiesBeanPropertyWriter[] filteredProperties)
     {
         super(typebuilderpropertiesfilteredProperties);
     }
    
    
Alternate copy constructor that can be used to construct standard BeanSerializer passing an instance of "compatible enough" source serializer.
 
     protected BeanSerializer(BeanSerializerBase src) {
         super(src);
     }
 
     protected BeanSerializer(BeanSerializerBase src,
             ObjectIdWriter objectIdWriter) {
         super(srcobjectIdWriter);
     }
 
     protected BeanSerializer(BeanSerializerBase src,
             ObjectIdWriter objectIdWriterObject filterId) {
         super(srcobjectIdWriterfilterId);
     }
     
     protected BeanSerializer(BeanSerializerBase srcString[] toIgnore) {
         super(srctoIgnore);
     }
 
     /*
     /**********************************************************
     /* Life-cycle: factory methods, fluent factories
     /**********************************************************
      */

    
Method for constructing dummy bean serializer; one that never outputs any properties
 
     public static BeanSerializer createDummy(JavaType forType)
     {
         return new BeanSerializer(forTypenullnull);
     }
 
     @Override
     public JsonSerializer<ObjectunwrappingSerializer(NameTransformer unwrapper) {
         return new UnwrappingBeanSerializer(thisunwrapper);
     }
 
     @Override
     public BeanSerializerBase withObjectIdWriter(ObjectIdWriter objectIdWriter) {
         return new BeanSerializer(thisobjectIdWriter);
     }
 
     @Override
     protected BeanSerializerBase withFilterId(Object filterId) {
         return new BeanSerializer(thisfilterId);
     }
 
     @Override
    protected BeanSerializerBase withIgnorals(String[] toIgnore) {
        return new BeanSerializer(thistoIgnore);
    }

    
Implementation has to check whether as-array serialization is possible reliably; if (and only if) so, will construct a com.fasterxml.jackson.databind.ser.impl.BeanAsArraySerializer, otherwise will return this serializer as is.
    @Override
    {
        /* Can not:
         * 
         * - have Object Id (may be allowed in future)
         * - have any getter
         * 
         */
        if (( == null)
                && ( == null)
                && ( == null)
                ) {
            return new BeanAsArraySerializer(this);
        }
        // already is one, so:
        return this;
    }
    
    /*
    /**********************************************************
    /* JsonSerializer implementation that differs between impls
    /**********************************************************
     */

    
Main serialization method that will delegate actual output to configured BeanPropertyWriter instances.
    @Override
    public final void serialize(Object beanJsonGenerator jgenSerializerProvider provider)
        throws IOExceptionJsonGenerationException
    {
        if ( != null) {
            _serializeWithObjectId(beanjgenprovidertrue);
            return;
        }
        jgen.writeStartObject();
        if ( != null) {
            serializeFieldsFiltered(beanjgenprovider);
        } else {
            serializeFields(beanjgenprovider);
        }
        jgen.writeEndObject();
    }
    
    /*
    /**********************************************************
    /* Standard methods
    /**********************************************************
     */
    @Override public String toString() {
        return "BeanSerializer for "+handledType().getName();
    }
New to GrepCode? Check out our FAQ X