Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.introspect;
  
  import java.util.List;
  
 
Helper class that allows using 2 introspectors such that one introspector acts as the primary one to use; and second one as a fallback used if the primary does not provide conclusive or useful result for a method.

An obvious consequence of priority is that it is easy to construct longer chains of introspectors by linking multiple pairs. Currently most likely combination is that of using the default Jackson provider, along with JAXB annotation introspector.

Note: up until 2.0, this class was an inner class of com.fasterxml.jackson.databind.AnnotationIntrospector; moved here for convenience.

Since:
2.1
 
     extends AnnotationIntrospector
     implements java.io.Serializable
 {
     private static final long serialVersionUID = 1L;
 
     protected final AnnotationIntrospector _primary_secondary;
 
     {
          = p;
          = s;
     }
 
     @Override
     public Version version() {
         return .version();
     }

    
Helper method for constructing a Pair from two given introspectors (if neither is null); or returning non-null introspector if one is null (and return just null if both are null)
 
     public static AnnotationIntrospector create(AnnotationIntrospector primary,
             AnnotationIntrospector secondary)
     {
         if (primary == null) {
             return secondary;
         }
         if (secondary == null) {
             return primary;
         }
         return new AnnotationIntrospectorPair(primarysecondary);
     }
 
     @Override
         return allIntrospectors(new ArrayList<AnnotationIntrospector>());
     }
 
     @Override
     {
         .allIntrospectors(result);
         .allIntrospectors(result);
         return result;
     }
     
     // // // Generic annotation properties, lookup
     
     @Override
     public boolean isAnnotationBundle(Annotation ann) {
         return .isAnnotationBundle(ann) || .isAnnotationBundle(ann);
     }
     
     /*
     /******************************************************
     /* General class annotations
     /******************************************************
      */
 
     @Override
    {
        PropertyName name1 = .findRootName(ac);
        if (name1 == null) {
            return .findRootName(ac);
        }
        if (name1.hasSimpleName()) {
            return name1;
        }
        // name1 is empty; how about secondary?
        PropertyName name2 = .findRootName(ac);
        return (name2 == null) ? name1 : name2;
    }
    @Override
    {
        String[] result = .findPropertiesToIgnore(ac);
        if (result == null) {
            result = .findPropertiesToIgnore(ac);
        }
        return result;            
    }
    @Override
    {
        Boolean result = .findIgnoreUnknownProperties(ac);
        if (result == null) {
            result = .findIgnoreUnknownProperties(ac);
        }
        return result;
    }        
    @Override
    {
        Boolean result = .isIgnorableType(ac);
        if (result == null) {
            result = .isIgnorableType(ac);
        }
        return result;
    }
    @Override
    public Object findFilterId(AnnotatedClass ac)
    {
        Object id = .findFilterId(ac);
        if (id == null) {
            id = .findFilterId(ac);
        }
        return id;
    }
    @Override
    {
        Object str = .findNamingStrategy(ac);
        if (str == null) {
            str = .findNamingStrategy(ac);
        }
        return str;
    }
    /*
    /******************************************************
    /* Property auto-detection
    /******************************************************
    */
    
    @Override
        VisibilityChecker<?> checker)
    {
        /* Note: to have proper priorities, we must actually call delegatees
         * in reverse order:
         */
        checker = .findAutoDetectVisibility(acchecker);
        return .findAutoDetectVisibility(acchecker);
    }
    /*
    /******************************************************
    /* Type handling
    /******************************************************
    */
    
    @Override
    public TypeResolverBuilder<?> findTypeResolver(MapperConfig<?> config,
            AnnotatedClass acJavaType baseType)
    {
        TypeResolverBuilder<?> b = .findTypeResolver(configacbaseType);
        if (b == null) {
            b = .findTypeResolver(configacbaseType);
        }
        return b;
    }
    @Override
            AnnotatedMember amJavaType baseType)
    {
        TypeResolverBuilder<?> b = .findPropertyTypeResolver(configambaseType);
        if (b == null) {
            b = .findPropertyTypeResolver(configambaseType);
        }
        return b;
    }
    @Override
            AnnotatedMember amJavaType baseType)
    {
        TypeResolverBuilder<?> b = .findPropertyContentTypeResolver(configambaseType);
        if (b == null) {
            b = .findPropertyContentTypeResolver(configambaseType);
        }
        return b;
    }
    
    @Override
    public List<NamedTypefindSubtypes(Annotated a)
    {
        List<NamedTypetypes1 = .findSubtypes(a);
        List<NamedTypetypes2 = .findSubtypes(a);
        if (types1 == null || types1.isEmpty()) return types2;
        if (types2 == null || types2.isEmpty()) return types1;
        ArrayList<NamedTyperesult = new ArrayList<NamedType>(types1.size() + types2.size());
        result.addAll(types1);
        result.addAll(types2);
        return result;
    }
    @Override
    public String findTypeName(AnnotatedClass ac)
    {
        String name = .findTypeName(ac);
        if (name == null || name.length() == 0) {
            name = .findTypeName(ac);                
        }
        return name;
    }
    
    // // // General member (field, method/constructor) annotations
    
    @Override        
    {
        ReferenceProperty ref = .findReferenceType(member);
        if (ref == null) {
            ref = .findReferenceType(member);
        }
        return ref
    }
    @Override        
    {
        NameTransformer value = .findUnwrappingNameTransformer(member);
        if (value == null) {
            value = .findUnwrappingNameTransformer(member);
        }
        return value;
    }
    @Override
    {
        Object value = .findInjectableValueId(m);
        if (value == null) {
            value = .findInjectableValueId(m);
        }
        return value;
    }
    @Override
    public boolean hasIgnoreMarker(AnnotatedMember m) {
        return .hasIgnoreMarker(m) || .hasIgnoreMarker(m);
    }
    
    @Override
    {
        Boolean value = .hasRequiredMarker(m);
        if (value == null) {
            value = .hasRequiredMarker(m);
        }
        return value;
    }
    
    // // // Serialization: general annotations
    @Override
    public Object findSerializer(Annotated am)
    {
        Object result = .findSerializer(am);
        if (result == null) {
            result = .findSerializer(am);
        }
        return result;
    }
    
    @Override
    {
        Object result = .findKeySerializer(a);
        if (result == null || result == JsonSerializer.None.class || result == NoClass.class) {
            result = .findKeySerializer(a);
        }
        return result;
    }
    @Override
    {
        Object result = .findContentSerializer(a);
        if (result == null || result == JsonSerializer.None.class || result == NoClass.class) {
            result = .findContentSerializer(a);
        }
        return result;
    }
    
    @Override
            JsonInclude.Include defValue)
    {
        /* This is bit trickier: need to combine results in a meaningful
         * way. Seems like it should be a disjoint; that is, most
         * restrictive value should be returned.
         * For enumerations, comparison is done by indexes, which
         * works: largest value is the last one, which is the most
         * restrictive value as well.
         */
        /* 09-Mar-2010, tatu: Actually, as per [JACKSON-256], it is probably better to just
         *    use strict overriding. Simpler, easier to understand.
         */
        // note: call secondary first, to give lower priority
        defValue = .findSerializationInclusion(adefValue);
        defValue = .findSerializationInclusion(adefValue);
        return defValue;
    }
    
    @Override
    public Class<?> findSerializationType(Annotated a)
    {
        Class<?> result = .findSerializationType(a);
        if (result == null) {
            result = .findSerializationType(a);
        }
        return result;
    }
    @Override
    public Class<?> findSerializationKeyType(Annotated amJavaType baseType)
    {
        Class<?> result = .findSerializationKeyType(ambaseType);
        if (result == null) {
            result = .findSerializationKeyType(ambaseType);
        }
        return result;
    }
    @Override
    public Class<?> findSerializationContentType(Annotated amJavaType baseType)
    {
        Class<?> result = .findSerializationContentType(ambaseType);
        if (result == null) {
            result = .findSerializationContentType(ambaseType);
        }
        return result;
    }
    
    @Override
    {
        if (result == null) {
            result = .findSerializationTyping(a);
        }
        return result;
    }
    @Override
    public Class<?>[] findViews(Annotated a)
    {
        /* Theoretically this could be trickier, if multiple introspectors
         * return non-null entries. For now, though, we'll just consider
         * first one to return non-null to win.
         */
        Class<?>[] result = .findViews(a);
        if (result == null) {
            result = .findViews(a);
        }
        return result;
    }
    @Override
    public Boolean isTypeId(AnnotatedMember member) {
        Boolean b = .isTypeId(member);
        if (b == null) {
            b = .isTypeId(member);
        }
        return b;
    }
    @Override
    public ObjectIdInfo findObjectIdInfo(Annotated ann) {
        ObjectIdInfo result = .findObjectIdInfo(ann);
        if (result == null) {
            result = .findObjectIdInfo(ann);
        }
        return result;
    }
    @Override
    public ObjectIdInfo findObjectReferenceInfo(Annotated annObjectIdInfo objectIdInfo) {
        // to give precedence for primary, must start with secondary:
        objectIdInfo = .findObjectReferenceInfo(annobjectIdInfo);
        objectIdInfo = .findObjectReferenceInfo(annobjectIdInfo);
        return objectIdInfo;
    }
    
    @Override
    public JsonFormat.Value findFormat(Annotated ann) {
        JsonFormat.Value result = .findFormat(ann);
        if (result == null) {
            result = .findFormat(ann);
        }
        return result;
    }
    @Override
    public PropertyName findWrapperName(Annotated ann) {
        PropertyName name = .findWrapperName(ann);
        if (name == null) {
            name = .findWrapperName(ann);
        } else if (name == .) {
            // does the other introspector have a better idea?
            PropertyName name2 = .findWrapperName(ann);
            if (name2 != null) {
                name = name2;
            }
        }
        return name;
    }
    
    // // // Serialization: class annotations
    @Override
        String[] result = .findSerializationPropertyOrder(ac);
        if (result == null) {
            result = .findSerializationPropertyOrder(ac);
        }
        return result;            
    }

    
Method for checking whether an annotation indicates that serialized properties for which no explicit is defined should be alphabetically (lexicograpically) ordered
    @Override
        if (result == null) {
            result = .findSerializationSortAlphabetically(ac);
        }
        return result;            
    }
    // // // Serialization: property annotations
    
    @Override
        // note: "use default" should not block explicit answer, so:
        if (n == null) {
            n = .findNameForSerialization(a);
        } else if (n == .) {
            PropertyName n2 = .findNameForSerialization(a);
            if (n2 != null) {
                n = n2;
            }
        }
        return n;
    }
    
    @Override
    public boolean hasAsValueAnnotation(AnnotatedMethod am)
    {
        return .hasAsValueAnnotation(am) || .hasAsValueAnnotation(am);
    }
    
    @Override
    public String findEnumValue(Enum<?> value)
    {
        String result = .findEnumValue(value);
        if (result == null) {
            result = .findEnumValue(value);
        }
        return result;
    }        
    // // // Deserialization: general annotations
    @Override
    public Object findDeserializer(Annotated am)
    {
        Object result = .findDeserializer(am);
        if (result == null) {
            result = .findDeserializer(am);
        }
        return result;
    }
    
    @Override
    {
        Object result = .findKeyDeserializer(am);
        if (result == null || result == KeyDeserializer.None.class || result == NoClass.class) {
            result = .findKeyDeserializer(am);
        }
        return result;
    }
    @Override
    {
        Object result = .findContentDeserializer(am);
        if (result == null || result == JsonDeserializer.None.class || result == NoClass.class) {
            result = .findContentDeserializer(am);
        }
        return result;
    }
    
    @Override
    public Class<?> findDeserializationType(Annotated amJavaType baseType)
    {
        Class<?> result = .findDeserializationType(ambaseType);
        if (result == null) {
            result = .findDeserializationType(ambaseType);
        }
        return result;
    }
    @Override
    public Class<?> findDeserializationKeyType(Annotated amJavaType baseKeyType)
    {
        Class<?> result = .findDeserializationKeyType(ambaseKeyType);
        if (result == null) {
            result = .findDeserializationKeyType(ambaseKeyType);
        }
        return result;
    }
    @Override
    public Class<?> findDeserializationContentType(Annotated amJavaType baseContentType)
    {
        Class<?> result = .findDeserializationContentType(ambaseContentType);
        if (result == null) {
            result = .findDeserializationContentType(ambaseContentType);
        }
        return result;
    }
    // // // Deserialization: class annotations
    @Override
    {
        Object result = .findValueInstantiator(ac);
        if (result == null) {
            result = .findValueInstantiator(ac);
        }
        return result;
    }
    @Override
    public Class<?> findPOJOBuilder(AnnotatedClass ac)
    {
            Class<?> result = .findPOJOBuilder(ac);
            if (result == null) {
                    result = .findPOJOBuilder(ac);
            }
            return result;
    }
    @Override
    {
        JsonPOJOBuilder.Value result = .findPOJOBuilderConfig(ac);
        if (result == null) {
            result = .findPOJOBuilderConfig(ac);
        }
        return result;
    }
    
    // // // Deserialization: method annotations
    @Override
    {
        // note: "use default" should not block explicit answer, so:
        if (n == null) {
            n = .findNameForDeserialization(a);
        } else if (n == .) {
            PropertyName n2 = .findNameForDeserialization(a);
            if (n2 != null) {
                n = n2;
            }
        }
        return n;
    }
    
    @Override
    public boolean hasAnySetterAnnotation(AnnotatedMethod am)
    {
    }
    @Override
    public boolean hasAnyGetterAnnotation(AnnotatedMethod am)
    {
    }
    
    @Override
    public boolean hasCreatorAnnotation(Annotated a)
    {
    }
 
    /*
    /******************************************************
    /* Deprecated methods
    /******************************************************
     */
    
    @Deprecated
    @Override
    public boolean isHandled(Annotation ann) {
        return .isHandled(ann) || .isHandled(ann);
    }
    // // // Deserialization: property annotations
    @Deprecated
    @Override
    {
        String result = .findDeserializationName(am);
        if (result == null) {
            result = .findDeserializationName(am);
        } else if (result.length() == 0) {
            /* Empty String is a default; can be overridden by
             * more explicit answer from secondary entry
             */
            String str2 = .findDeserializationName(am);
            if (str2 != null) {
                result = str2;
            }
        }
        return result;
    }
    
    @Deprecated
    @Override
    {
        String result = .findDeserializationName(af);
        if (result == null) {
            result = .findDeserializationName(af);
        } else if (result.length() == 0) {
            /* Empty String is a default; can be overridden by
             * more explicit answer from secondary entry
             */
            String str2 = .findDeserializationName(af);
            if (str2 != null) {
                result = str2;
            }
        }
        return result;
    }
    @Deprecated
    @Override
    {
        String result = .findDeserializationName(param);
        if (result == null) {
            result = .findDeserializationName(param);
        }
        return result;
    }
    // // // Serialization: property annotations
    
    @Deprecated
    @Override
    {
        String result = .findSerializationName(am);
        if (result == null) {
            result = .findSerializationName(am);
        } else if (result.length() == 0) {
            /* Empty String is a default; can be overridden by
             * more explicit answer from secondary entry
             */
            String str2 = .findSerializationName(am);
            if (str2 != null) {
                result = str2;
            }
        }
        return result;
    }
    @Deprecated
    @Override
    {
        String result = .findSerializationName(af);
        if (result == null) {
            result = .findSerializationName(af);
        } else if (result.length() == 0) {
            /* Empty String is a default; can be overridden by
             * more explicit answer from secondary entry
             */
            String str2 = .findSerializationName(af);
            if (str2 != null) {
                result = str2;
            }
        }
        return result;
    }
New to GrepCode? Check out our FAQ X