Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.jsontype.impl;
  
  import java.util.*;
  
 
 public class StdSubtypeResolver
     extends SubtypeResolver
     implements java.io.Serializable
 {
     private static final long serialVersionUID = 1L;
 
 
     public StdSubtypeResolver() { }
     
     /*
     /**********************************************************
     /* Public API
     /**********************************************************
      */
 
     @Override    
     public void registerSubtypes(NamedType... types)
     {
         if ( == null) {
              = new LinkedHashSet<NamedType>();
         }
         for (NamedType type : types) {
             .add(type);
         }
     }
 
     @Override
     public void registerSubtypes(Class<?>... classes)
     {
         NamedType[] types = new NamedType[classes.length];
         for (int i = 0, len = classes.lengthi < len; ++i) {
             types[i] = new NamedType(classes[i]);
         }
         registerSubtypes(types);
     }

    

Deprecated:
Since 2.1
 
     @Deprecated
     @Override
         MapperConfig<?> configAnnotationIntrospector ai)
     {
         return collectAndResolveSubtypes(propertyconfigainull);
     }
    
    

Parameters:
property Base member to use for type resolution: either annotated type (class), or property (field, getter/setter)
Since:
2.1
 
     @Override
         MapperConfig<?> configAnnotationIntrospector aiJavaType baseType)
     {
         // for backwards compatibility, must allow null here:
         Class<?> rawBase = (baseType == null) ? property.getRawType() : baseType.getRawClass();
         
         HashMap<NamedTypeNamedTypecollected = new HashMap<NamedTypeNamedType>();
         // start with registered subtypes (which have precedence)
         if ( != null) {
             for (NamedType subtype : ) {
                 // is it a subtype of root type?
                 if (rawBase.isAssignableFrom(subtype.getType())) { // yes
                     AnnotatedClass curr = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), aiconfig);
                     _collectAndResolve(currsubtypeconfigaicollected);
                 }
             }
         }
         
         // then annotated types for property itself
         Collection<NamedTypest = ai.findSubtypes(property);
         if (st != null) {
             for (NamedType nt : st) {
                 AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(nt.getType(), aiconfig);
                 _collectAndResolve(acntconfigaicollected);
             }            
         }
         
         NamedType rootType = new NamedType(rawBasenull);
         AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(rawBaseaiconfig);
            
        // and finally subtypes via annotations from base type (recursively)
        _collectAndResolve(acrootTypeconfigaicollected);
        return new ArrayList<NamedType>(collected.values());
    }
    @Override
            MapperConfig<?> configAnnotationIntrospector ai)
    {
        HashMap<NamedTypeNamedTypesubtypes = new HashMap<NamedTypeNamedType>();
        // [JACKSON-257] then consider registered subtypes (which have precedence over annotations)
        if ( != null) {
            Class<?> rawBase = type.getRawType();
            for (NamedType subtype : ) {
                // is it a subtype of root type?
                if (rawBase.isAssignableFrom(subtype.getType())) { // yes
                    AnnotatedClass curr = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), aiconfig);
                    _collectAndResolve(currsubtypeconfigaisubtypes);
                }
            }
        }
        // and then check subtypes via annotations from base type (recursively)
        NamedType rootType = new NamedType(type.getRawType(), null);
        _collectAndResolve(typerootTypeconfigaisubtypes);
        return new ArrayList<NamedType>(subtypes.values());
    }
    /*
    /**********************************************************
    /* Internal methods
    /**********************************************************
     */
    
    
Method called to find subtypes for a specific type (class)
    protected void _collectAndResolve(AnnotatedClass annotatedTypeNamedType namedType,
            MapperConfig<?> configAnnotationIntrospector ai,
            HashMap<NamedTypeNamedTypecollectedSubtypes)
    {
        if (!namedType.hasName()) {
            String name = ai.findTypeName(annotatedType);
            if (name != null) {
                namedType = new NamedType(namedType.getType(), name);
            }
        }
        // First things first: is base type itself included?
        if (collectedSubtypes.containsKey(namedType)) {
            // if so, no recursion; however, may need to update name?
            if (namedType.hasName()) {
                NamedType prev = collectedSubtypes.get(namedType);
                if (!prev.hasName()) {
                    collectedSubtypes.put(namedTypenamedType);
                }
            }
            return;
        }
        // if it wasn't, add and check subtypes recursively
        collectedSubtypes.put(namedTypenamedType);
        Collection<NamedTypest = ai.findSubtypes(annotatedType);
        if (st != null && !st.isEmpty()) {
            for (NamedType subtype : st) {
                AnnotatedClass subtypeClass = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), aiconfig);
                // One more thing: name may be either in reference, or in subtype:
                if (!subtype.hasName()) {
                    subtype = new NamedType(subtype.getType(), ai.findTypeName(subtypeClass));
                }
                _collectAndResolve(subtypeClasssubtypeconfigaicollectedSubtypes);
            }
        }
    }
New to GrepCode? Check out our FAQ X