Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.ser;
  
  import java.util.*;
  
Builder class used for aggregating deserialization information about a POJO, in order to build a com.fasterxml.jackson.databind.JsonSerializer for serializing intances. Main reason for using separate builder class is that this makes it easier to make actual serializer class fully immutable.
 
 public class BeanSerializerBuilder
 {
     private final static BeanPropertyWriter[] NO_PROPERTIES = new BeanPropertyWriter[0];
 
     /*
     /**********************************************************
     /* Basic configuration we start with
     /**********************************************************
      */
 
     final protected BeanDescription _beanDesc;
 
     protected SerializationConfig _config;
     
     /*
     /**********************************************************
     /* Accumulated information about properties
     /**********************************************************
      */

    
Bean properties, in order of serialization
 
     protected List<BeanPropertyWriter_properties;

    
Optional array of filtered property writers; if null, no view-based filtering is performed.
 
     protected BeanPropertyWriter[] _filteredProperties;
    
    
Writer used for "any getter" properties, if any.
 
     protected AnyGetterWriter _anyGetter;

    
Id of the property filter to use for POJO, if any.
 
     protected Object _filterId;

    
Property that is used for type id (and not serialized as regular property)
 
     protected AnnotatedMember _typeId;

    
Object responsible for serializing Object Ids for the handled type, if any.
 
     protected ObjectIdWriter _objectIdWriter;
     
     /*
     /**********************************************************
     /* Construction and setter methods
     /**********************************************************
      */
     
     public BeanSerializerBuilder(BeanDescription beanDesc) {
          = beanDesc;
     }

    
Copy-constructor that may be used for sub-classing
 
     protected BeanSerializerBuilder(BeanSerializerBuilder src) {
          = src._beanDesc;
          = src._properties;
          = src._filteredProperties;
          = src._anyGetter;
          = src._filterId;
     }

    
Initialization method called right after construction, to specify configuration to use.

Note: ideally should be passed in constructor, but for backwards compatibility, needed to add a setter instead

Since:
2.1
 
    protected void setConfig(SerializationConfig config) {
         = config;
    }
    
    public void setProperties(List<BeanPropertyWriterproperties) {
         = properties;
    }
    public void setFilteredProperties(BeanPropertyWriter[] properties) {
         = properties;
    }
    
    public void setAnyGetter(AnyGetterWriter anyGetter) {
         = anyGetter;
    }
    public void setFilterId(Object filterId) {
         = filterId;
    }
    
    public void setTypeId(AnnotatedMember idProp) {
        // Not legal to use multiple ones...
        if ( != null) {
            throw new IllegalArgumentException("Multiple type ids specified with "++" and "+idProp);
        }
         = idProp;
    }
    public void setObjectIdWriter(ObjectIdWriter w) {
         = w;
    }
    
    /*
    /**********************************************************
    /* Accessors for things BeanSerializer cares about:
    /* note -- likely to change between minor revisions
    /* by new methods getting added.
    /**********************************************************
     */
    public AnnotatedClass getClassInfo() { return .getClassInfo(); }
    
    public BeanDescription getBeanDescription() { return ; }
    public List<BeanPropertyWritergetProperties() { return ; }
    public boolean hasProperties() {
        return ( != null) && (.size() > 0);
    }
    
    public AnyGetterWriter getAnyGetter() { return ; }
    
    public Object getFilterId() { return ; }
    public AnnotatedMember getTypeId() { return ; }
    public ObjectIdWriter getObjectIdWriter() { return ; }
    
    /*
    /**********************************************************
    /* Build methods for actually creating serializer instance
    /**********************************************************
     */
    
    
Method called to create BeanSerializer instance with all accumulated information. Will construct a serializer if we have enough information, or return null if not.
    public JsonSerializer<?> build()
    {
        BeanPropertyWriter[] properties;
        // No properties or any getter? No real serializer; caller gets to handle
        if ( == null || .isEmpty()) {
            if ( == null) {
                return null;
            }
            properties = ;
        } else {
            properties = .toArray(new BeanPropertyWriter[.size()]);
            
        }
        return new BeanSerializer(.getType(), this,
                properties);
    }
    
    
Factory method for constructing an "empty" serializer; one that outputs no properties (but handles JSON objects properly, including type information)
    public BeanSerializer createDummy() {
        return BeanSerializer.createDummy(.getType());
    }
New to GrepCode? Check out our FAQ X