Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.jsontype.impl;
  
  
Default com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder implementation.

Author(s):
tatu
 
 public class StdTypeResolverBuilder
 {
     // Configuration settings:
 
     protected JsonTypeInfo.Id _idType;
 
     protected JsonTypeInfo.As _includeAs;
 
     protected String _typeProperty;

    
Whether type id should be exposed to deserializers or not
 
     protected boolean _typeIdVisible = false;
    
    
Default class to use in case type information is not available or is broken.
 
     protected Class<?> _defaultImpl;
     
     // Objects
     
     protected TypeIdResolver _customIdResolver;
     
     /*
     /**********************************************************
     /* Construction, initialization, actual building
     /**********************************************************
      */
 
     public StdTypeResolverBuilder() { }
 
     public static StdTypeResolverBuilder noTypeInfoBuilder() {
         return new StdTypeResolverBuilder().init(..null);
     }
     
 //  @Override
     public StdTypeResolverBuilder init(JsonTypeInfo.Id idTypeTypeIdResolver idRes)
     {
         // sanity checks
         if (idType == null) {
             throw new IllegalArgumentException("idType can not be null");
         }
          = idType;
          = idRes;
         // Let's also initialize property name as per idType default
          = idType.getDefaultPropertyName();
         return this;
     }
     
 //  @Override
             JavaType baseTypeCollection<NamedTypesubtypes)
     {
         if ( == ..) {
             return null;
         }
         TypeIdResolver idRes = idResolver(configbaseTypesubtypestruefalse);
         switch () {
         case :
             return new AsArrayTypeSerializer(idResnull);
         case :
             return new AsPropertyTypeSerializer(idResnull,
                     );
         case :
             return new AsWrapperTypeSerializer(idResnull);
         case :
             return new AsExternalTypeSerializer(idResnull,
                     );
         }
         throw new IllegalStateException("Do not know how to construct standard type serializer for inclusion type: "+);
     }
     
 //  @Override
             JavaType baseTypeCollection<NamedTypesubtypes)
     {
         if ( == ..) {
             return null;
        }
        TypeIdResolver idRes = idResolver(configbaseTypesubtypesfalsetrue);
        
        // First, method for converting type info to type id:
        switch () {
        case :
            return new AsArrayTypeDeserializer(baseTypeidRes,
                    );
        case :
            return new AsPropertyTypeDeserializer(baseTypeidRes,
                    );
        case :
            return new AsWrapperTypeDeserializer(baseTypeidRes,
                    );
        case :
            return new AsExternalTypeDeserializer(baseTypeidRes,
                    );
        }
        throw new IllegalStateException("Do not know how to construct standard type serializer for inclusion type: "+);
    }
    /*
    /**********************************************************
    /* Construction, configuration
    /**********************************************************
     */
//  @Override
    public StdTypeResolverBuilder inclusion(JsonTypeInfo.As includeAs) {
        if (includeAs == null) {
            throw new IllegalArgumentException("includeAs can not be null");
        }
         = includeAs;
        return this;
    }

    
Method for constructing an instance with specified type property name (property name to use for type id when using "as-property" inclusion).
//  @Override
    public StdTypeResolverBuilder typeProperty(String typeIdPropName)
    {
        // ok to have null/empty; will restore to use defaults
        if (typeIdPropName == null || typeIdPropName.length() == 0) {
            typeIdPropName = .getDefaultPropertyName();
        }
         = typeIdPropName;
        return this;
    }
//  @Override
    public StdTypeResolverBuilder defaultImpl(Class<?> defaultImpl)
    {
         = defaultImpl;
        return this;
    }
//  @Override
    public StdTypeResolverBuilder typeIdVisibility(boolean isVisible) {
         = isVisible;
        return this;
    }
    
    /*
    /**********************************************************
    /* Accessors
    /**********************************************************
     */
    public String getTypeProperty() { return ; }
//  @Override
    public Class<?> getDefaultImpl() {
        return ;
    }
    public boolean isTypeIdVisible() { return ; }
    
    /*
    /**********************************************************
    /* Internal methods
    /**********************************************************
     */
    
    
Helper method that will either return configured custom type id resolver, or construct a standard resolver given configuration.
    protected TypeIdResolver idResolver(MapperConfig<?> config,
            JavaType baseTypeCollection<NamedTypesubtypes,
            boolean forSerboolean forDeser)
    {
        // Custom id resolver?
        if ( != null) {
            return ;
        }
        if ( == null) {
            throw new IllegalStateException("Can not build, 'init()' not yet called");
        }
        switch () {
        case :
            return new ClassNameIdResolver(baseTypeconfig.getTypeFactory());
        case :
            return new MinimalClassNameIdResolver(baseTypeconfig.getTypeFactory());
        case :
            return TypeNameIdResolver.construct(configbaseTypesubtypesforSerforDeser);
        case // hmmh. should never get this far with 'none'
            return null;
        case // need custom resolver...
        }
        throw new IllegalStateException("Do not know how to construct standard type id resolver for idType: "+);
    }
New to GrepCode? Check out our FAQ X