Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind;
  
  import java.util.*;
  
Object that contains baseline configuration for serialization process. An instance is owned by ObjectMapper, which passes an immutable instance for serialization process to SerializerProvider and com.fasterxml.jackson.databind.ser.SerializerFactory (either directly, or through ObjectWriter.

Note that instances are considered immutable and as such no copies should need to be created for sharing; all copying is done with "fluent factory" methods. Note also that unlike with Jackson 1, these instances can not be assigned to ObjectMapper; in fact, application code should rarely interact directly with these instance (unlike core Jackson code)

 
 public final class SerializationConfig
     implements java.io.Serializable // since 2.1
 {
     // for 2.1.0:
     private static final long serialVersionUID = 8849092838541724233L;

    
Set of features enabled; actual type (kind of features) depends on sub-classes.
 
     protected final int _serFeatures;
    
    
Which Bean/Map properties are to be included in serialization? Default settings is to include all regardless of value; can be changed to only include non-null properties, or properties with non-default values.
 
     protected JsonInclude.Include _serializationInclusion = null;
    
    
Object used for resolving filter ids to filter instances. Non-null if explicitly defined; null by default.
 
     protected final FilterProvider _filterProvider;
     
     /*
     /**********************************************************
     /* Life-cycle, constructors
     /**********************************************************
      */

    
Constructor used by ObjectMapper to create default configuration object instance.
 
     public SerializationConfig(BaseSettings base,
             SubtypeResolver strMap<ClassKey,Class<?>> mixins)
     {
         super(basestrmixins);
          = null;
     }
     
     {
         super(srcstr);
          = src._serFeatures;
          = src._serializationInclusion;
          = src._filterProvider;
     }
 
             int mapperFeaturesint serFeatures)
     {
         super(srcmapperFeatures);
          = serFeatures;
          = src._serializationInclusion;
          = src._filterProvider;
     }
     
     private SerializationConfig(SerializationConfig srcBaseSettings base)
     {
         super(srcbase);
          = src._serFeatures;
         = src._serializationInclusion;
         = src._filterProvider;
    }
    {
        super(src);
         = src._serFeatures;
         = src._serializationInclusion;
         = filters;
    }
    private SerializationConfig(SerializationConfig srcClass<?> view)
    {
        super(srcview);
         = src._serFeatures;
         = src._serializationInclusion;
         = src._filterProvider;
    }
    {
        super(src);
         = src._serFeatures;
         = incl;
         = src._filterProvider;
    }
    private SerializationConfig(SerializationConfig srcString rootName)
    {
        super(srcrootName);
         = src._serFeatures;
         = src._serializationInclusion;
         = src._filterProvider;
    }

    

Since:
2.1
    protected SerializationConfig(SerializationConfig srcMap<ClassKey,Class<?>> mixins)
    {
        super(srcmixins);
         = src._serFeatures;
         = src._serializationInclusion;
         = src._filterProvider;
    }
    
    /*
    /**********************************************************
    /* Life-cycle, factory methods from MapperConfig
    /**********************************************************
     */

    
Fluent factory method that will construct and return a new configuration object instance with specified features enabled.
    @Override
    public SerializationConfig with(MapperFeature... features)
    {
        int newMapperFlags = ;
        for (MapperFeature f : features) {
            newMapperFlags |= f.getMask();
        }
        return (newMapperFlags == ) ? this
                : new SerializationConfig(thisnewMapperFlags);
    }
    
    
Fluent factory method that will construct and return a new configuration object instance with specified features disabled.
    @Override
    public SerializationConfig without(MapperFeature... features)
    {
        int newMapperFlags = ;
        for (MapperFeature f : features) {
             newMapperFlags &= ~f.getMask();
        }
        return (newMapperFlags == ) ? this
                : new SerializationConfig(thisnewMapperFlags);
    }
    @Override
        return _withBase(.withAnnotationIntrospector(ai));
    }
    @Override
    }
    @Override
    }
    @Override
        return _withBase(.withClassIntrospector(ci));
    }
    
    
In addition to constructing instance with specified date format, will enable or disable SerializationFeature.WRITE_DATES_AS_TIMESTAMPS (enable if format set as null; disable if non-null)
    @Override
    public SerializationConfig with(DateFormat df) {
        SerializationConfig cfg =  new SerializationConfig(this.withDateFormat(df));
        // Also need to toggle this feature based on existence of date format:
        if (df == null) {
            cfg = cfg.with(.);
        } else {
            cfg = cfg.without(.);
        }
        return cfg;
    }
    
    @Override
        return _withBase(.withHandlerInstantiator(hi));
    }
    
    @Override
        return _withBase(.withPropertyNamingStrategy(pns));
    }
    @Override
    public SerializationConfig withRootName(String rootName) {
        if (rootName == null) {
            if ( == null) {
                return this;
            }
        } else if (rootName.equals()) {
            return this;
        }
        return new SerializationConfig(thisrootName);
    }
    @Override
    public SerializationConfig with(SubtypeResolver str) {
        return (str == )? this : new SerializationConfig(thisstr);
    }
    @Override
    public SerializationConfig with(TypeFactory tf) {
        return _withBase(.withTypeFactory(tf));
    }
    @Override
    public SerializationConfig with(TypeResolverBuilder<?> trb) {
        return _withBase(.withTypeResolverBuilder(trb));
    }
    
    @Override
    public SerializationConfig withView(Class<?> view) {
        return ( == view) ? this : new SerializationConfig(thisview);
    }
    @Override
    public SerializationConfig with(VisibilityChecker<?> vc) {
        return _withBase(.withVisibilityChecker(vc));
    }
    @Override
        return _withBase(.withVisibility(forMethodvisibility));
    }
    @Override
    public SerializationConfig with(Locale l) {
        return _withBase(.with(l));
    }
    @Override
    public SerializationConfig with(TimeZone tz) {
        return _withBase(.with(tz));
    }
    @Override
    public SerializationConfig with(Base64Variant base64) {
        return _withBase(.with(base64));
    }
    
    private final SerializationConfig _withBase(BaseSettings newBase) {
        return ( == newBase) ? this : new SerializationConfig(thisnewBase);
    }
    
    /*
    /**********************************************************
    /* Life-cycle, SerializationConfig specific factory methods
    /**********************************************************
     */
        
    
Fluent factory method that will construct and return a new configuration object instance with specified feature enabled.
    {
        int newSerFeatures =  | feature.getMask();
        return (newSerFeatures == ) ? this
                : new SerializationConfig(thisnewSerFeatures);
    }

    
Fluent factory method that will construct and return a new configuration object instance with specified features enabled.
    {
        int newSerFeatures =  | first.getMask();
        for (SerializationFeature f : features) {
            newSerFeatures |= f.getMask();
        }
        return (newSerFeatures == ) ? this
                : new SerializationConfig(thisnewSerFeatures);
    }
    
    
Fluent factory method that will construct and return a new configuration object instance with specified features enabled.
    {
        int newSerFeatures = ;
        for (SerializationFeature f : features) {
            newSerFeatures |= f.getMask();
        }
        return (newSerFeatures == ) ? this
                : new SerializationConfig(thisnewSerFeatures);
    }

    
Fluent factory method that will construct and return a new configuration object instance with specified feature disabled.
    {
        int newSerFeatures =  & ~feature.getMask();
        return (newSerFeatures == ) ? this
                : new SerializationConfig(thisnewSerFeatures);
    }

    
Fluent factory method that will construct and return a new configuration object instance with specified features disabled.
    {
        int newSerFeatures =  & ~first.getMask();
        for (SerializationFeature f : features) {
            newSerFeatures &= ~f.getMask();
        }
        return (newSerFeatures == ) ? this
                : new SerializationConfig(thisnewSerFeatures);
    }

    
Fluent factory method that will construct and return a new configuration object instance with specified features disabled.
    {
        int newSerFeatures = ;
        for (SerializationFeature f : features) {
            newSerFeatures &= ~f.getMask();
        }
        return (newSerFeatures == ) ? this
                : new SerializationConfig(thisnewSerFeatures);
    }
    
    public SerializationConfig withFilters(FilterProvider filterProvider) {
        return (filterProvider == ) ? this : new SerializationConfig(thisfilterProvider);
    }
        return ( == incl) ? this:  new SerializationConfig(thisincl);
    }
    
    /*
    /**********************************************************
    /* MapperConfig implementation/overrides
    /**********************************************************
     */
    
    @Override
    public boolean useRootWrapping()
    {
        if ( != null) { // empty String disables wrapping; non-empty enables
            return (.length() > 0);
        }
    }
    
    @Override
    {
        /* 29-Jul-2009, tatu: it's now possible to disable use of
         *   annotations; can be done using "no-op" introspector
         */
        if (isEnabled(.)) {
            return super.getAnnotationIntrospector();
        }
        return AnnotationIntrospector.nopInstance();
    }

    
Accessor for getting bean description that only contains class annotations: useful if no getter/setter/creator information is needed.
    @Override
        return getClassIntrospector().forClassAnnotations(thistypethis);
    }

    
Accessor for getting bean description that only contains immediate class annotations: ones from the class, and its direct mix-in, if any, but not from super types.
    @Override
        return getClassIntrospector().forDirectClassAnnotations(thistypethis);
    }
    
    @Override
    {
        VisibilityChecker<?> vchecker = super.getDefaultVisibilityChecker();
            vchecker = vchecker.withGetterVisibility(.);
        }
        // then global overrides (disabling)
            vchecker = vchecker.withIsGetterVisibility(.);
        }
        if (!isEnabled(.)) {
            vchecker = vchecker.withFieldVisibility(.);
        }
        return vchecker;
    }
    
    /*
    /**********************************************************
    /* Configuration: other
    /**********************************************************
     */
    public final boolean isEnabled(SerializationFeature f) {
        return ( & f.getMask()) != 0;
    }
    
    public final int getSerializationFeatures() {
        return ;
    }
    
    {
        if ( != null) {
            return ;
        }
        return ..;
    }
    
    
Method for getting provider used for locating filters given id (which is usually provided with filter annotations). Will be null if no provided was set for ObjectWriter (or if serialization directly called from ObjectMapper)
    public FilterProvider getFilterProvider() {
        return ;
    }
    /*
    /**********************************************************
    /* Introspection methods
    /**********************************************************
     */

    
Method that will introspect full bean properties for the purpose of building a bean serializer
    @SuppressWarnings("unchecked")
    public <T extends BeanDescription> T introspect(JavaType type) {
        return (T) getClassIntrospector().forSerialization(thistypethis);
    }
    
    /*
    /**********************************************************
    /* Debug support
    /**********************************************************
     */
    
    @Override public String toString()
    {
        return "[SerializationConfig: flags=0x"+Integer.toHexString()+"]";
    }
New to GrepCode? Check out our FAQ X