Class ClassUtil


  • public final class ClassUtil
    extends java.lang.Object
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ClassUtil.Ctor
      Value class used for caching Constructor declarations; used because caching done by JDK appears to be somewhat inefficient for some use cases.
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static java.lang.String apostrophed​(java.lang.String text)
      Returns either 'text' (single-quoted) or [null].
      static java.lang.String backticked​(java.lang.String text)
      Returns either `text` (backtick-quoted) or [null].
      static java.lang.String canBeABeanType​(java.lang.Class<?> type)  
      static void checkAndFixAccess​(java.lang.reflect.Member member)
      Deprecated.
      Since 2.7 call variant that takes boolean flag.
      static void checkAndFixAccess​(java.lang.reflect.Member member, boolean evenIfAlreadyPublic)
      Method that is called if a Member may need forced access, to force a field, method or constructor to be accessible: this is done by calling AccessibleObject.setAccessible(boolean).
      static java.lang.String classNameOf​(java.lang.Object inst)
      Helper method used to construct appropriate description when passed either type (Class) or an instance; in latter case, class of instance is to be used.
      static java.lang.Class<?> classOf​(java.lang.Object inst)  
      static void closeOnFailAndThrowAsIOE​(JsonGenerator g, java.io.Closeable toClose, java.lang.Exception fail)
      Helper method that encapsulate logic in trying to close given Closeable in case of failure; useful mostly in forcing flush()ing as otherwise error conditions tend to be hard to diagnose.
      static void closeOnFailAndThrowAsIOE​(JsonGenerator g, java.lang.Exception fail)
      Helper method that encapsulate logic in trying to close output generator in case of failure; useful mostly in forcing flush()ing as otherwise error conditions tend to be hard to diagnose.
      static <T> T createInstance​(java.lang.Class<T> cls, boolean canFixAccess)
      Method that can be called to try to create an instantiate of specified type.
      static java.lang.Object defaultValue​(java.lang.Class<?> cls)
      Helper method used to get default value for wrappers used for primitive types (0 for Integer etc)
      static <T> java.util.Iterator<T> emptyIterator()  
      static java.lang.String exceptionMessage​(java.lang.Throwable t)
      Helper method that returns Throwable.getMessage() for all other exceptions except for (a) JacksonException, for which getOriginalMessage() is returned, and (b) InvocationTargetException, for which the cause's message is returned, if available.
      static java.lang.annotation.Annotation[] findClassAnnotations​(java.lang.Class<?> cls)  
      static <T> java.lang.reflect.Constructor<T> findConstructor​(java.lang.Class<T> cls, boolean forceAccess)  
      static java.lang.Class<? extends java.lang.Enum<?>> findEnumType​(java.lang.Class<?> cls)
      Helper method that can be used to dynamically figure out formal enumeration type (class) for given class of an enumeration value.
      static java.lang.Class<? extends java.lang.Enum<?>> findEnumType​(java.lang.Enum<?> en)
      Helper method that can be used to dynamically figure out formal enumeration type (class) for given enumeration.
      static java.lang.Class<? extends java.lang.Enum<?>> findEnumType​(java.util.EnumMap<?,​?> m)
      Helper method that can be used to dynamically figure out enumeration type of given EnumSet, without having access to its declaration.
      static java.lang.Class<? extends java.lang.Enum<?>> findEnumType​(java.util.EnumSet<?> s)
      Helper method that can be used to dynamically figure out enumeration type of given EnumSet, without having access to its declaration.
      static <T extends java.lang.annotation.Annotation>
      java.lang.Enum<?>
      findFirstAnnotatedEnumValue​(java.lang.Class<java.lang.Enum<?>> enumClass, java.lang.Class<T> annotationClass)
      A method that will look for the first Enum value annotated with the given Annotation.
      static java.util.List<java.lang.Class<?>> findRawSuperTypes​(java.lang.Class<?> cls, java.lang.Class<?> endBefore, boolean addClassItself)  
      static java.util.List<java.lang.Class<?>> findSuperClasses​(java.lang.Class<?> cls, java.lang.Class<?> endBefore, boolean addClassItself)
      Method for finding all super classes (but not super interfaces) of given class, starting with the immediate super class and ending in the most distant one.
      static java.util.List<JavaType> findSuperTypes​(JavaType type, java.lang.Class<?> endBefore, boolean addClassItself)
      Method that will find all sub-classes and implemented interfaces of a given class or interface.
      static java.util.List<java.lang.Class<?>> findSuperTypes​(java.lang.Class<?> cls, java.lang.Class<?> endBefore)
      Deprecated.
      static java.util.List<java.lang.Class<?>> findSuperTypes​(java.lang.Class<?> cls, java.lang.Class<?> endBefore, java.util.List<java.lang.Class<?>> result)
      Deprecated.
      static java.lang.String getClassDescription​(java.lang.Object classOrInstance)
      Helper method used to construct appropriate description when passed either type (Class) or an instance; in latter case, class of instance is to be used.
      static java.lang.reflect.Method[] getClassMethods​(java.lang.Class<?> cls)
      Helper method that gets methods declared in given class; usually a simple thing, but sometimes (as per [databind#785]) more complicated, depending on classloader setup.
      static ClassUtil.Ctor[] getConstructors​(java.lang.Class<?> cls)  
      static java.lang.reflect.Field[] getDeclaredFields​(java.lang.Class<?> cls)
      Deprecated.
      since 2.11 (just call Class method directly)
      static java.lang.reflect.Method[] getDeclaredMethods​(java.lang.Class<?> cls)
      Deprecated.
      since 2.11 (just call Class method directly)
      static java.lang.Class<?> getDeclaringClass​(java.lang.Class<?> cls)  
      static java.lang.Class<?> getEnclosingClass​(java.lang.Class<?> cls)  
      static java.lang.reflect.Type[] getGenericInterfaces​(java.lang.Class<?> cls)  
      static java.lang.reflect.Type getGenericSuperclass​(java.lang.Class<?> cls)  
      static java.lang.Class<?> getOuterClass​(java.lang.Class<?> type)
      Method for finding enclosing class for non-static inner classes
      static java.lang.String getPackageName​(java.lang.Class<?> cls)
      Deprecated.
      Since 2.12 (just call methods directly or check class name)
      static java.lang.Throwable getRootCause​(java.lang.Throwable t)
      Method that can be used to find the "root cause", innermost of chained (wrapped) exceptions.
      static java.lang.String getTypeDescription​(JavaType fullType)
      Helper method to create and return "backticked" description of given resolved type (or, "null" if null passed), similar to return vaue of getClassDescription(Object).
      static boolean hasClass​(java.lang.Object inst, java.lang.Class<?> raw)  
      static boolean hasEnclosingMethod​(java.lang.Class<?> cls)  
      static boolean hasGetterSignature​(java.lang.reflect.Method m)
      Deprecated.
      Since 2.6 not used; may be removed before 3.x
      static boolean isBogusClass​(java.lang.Class<?> cls)  
      static boolean isCollectionMapOrArray​(java.lang.Class<?> type)  
      static boolean isConcrete​(java.lang.Class<?> type)
      Helper method that checks if given class is a concrete one; that is, not an interface or abstract class.
      static boolean isConcrete​(java.lang.reflect.Member member)  
      static boolean isEnumType​(java.lang.Class<?> rawType)
      Helper method that encapsulates reliable check on whether given raw type "is an Enum", that is, is or extends Enum.
      static boolean isJacksonStdImpl​(java.lang.Class<?> implClass)  
      static boolean isJacksonStdImpl​(java.lang.Object impl)
      Method that can be called to determine if given Object is the default implementation Jackson uses; as opposed to a custom serializer installed by a module or calling application.
      static boolean isJDKClass​(java.lang.Class<?> rawType)
      Accessor for checking whether given Class is under Java package of java.* or javax.* (including all sub-packages).
      static java.lang.String isLocalType​(java.lang.Class<?> type, boolean allowNonStatic)  
      static boolean isNonStaticInnerClass​(java.lang.Class<?> cls)  
      static boolean isObjectOrPrimitive​(java.lang.Class<?> cls)  
      static boolean isProxyType​(java.lang.Class<?> type)
      Helper method used to weed out dynamic Proxy types; types that do not expose concrete method API that we could use to figure out automatic Bean (property) based serialization.
      static boolean isRecordType​(java.lang.Class<?> cls)
      Helper method for detecting Java14-added new Record types
      static java.lang.String name​(PropertyName name)
      Returns either single-quoted (apostrophe) 'name' (if name not null), or "[null]" if name is null.
      static java.lang.String name​(java.lang.String name)
      Returns either single-quoted (apostrophe) 'name' (if name not null), or "[null]" if name is null.
      static java.lang.String nameOf​(Named named)
      Returns either single-quoted (apostrophe) 'named.getName()' (if named not null), or "[null]" if named is null.
      static java.lang.String nameOf​(java.lang.Class<?> cls)
      Returns either `cls.getName()` (if `cls` not null), or "[null]" if `cls` is null.
      static <T> T nonNull​(T valueOrNull, T defaultValue)  
      static java.lang.String nonNullString​(java.lang.String str)  
      static java.lang.String nullOrToString​(java.lang.Object value)  
      static java.lang.Class<?> primitiveType​(java.lang.Class<?> type)
      Method that can be used to find primitive type for given class if (but only if) it is either wrapper type or primitive type; returns null if type is neither.
      static java.lang.String quotedOr​(java.lang.Object str, java.lang.String forNull)
      Returns either quoted value (with double-quotes) -- if argument non-null String -- or String NULL (no quotes) (if null).
      static java.lang.Class<?> rawClass​(JavaType t)  
      static void throwAsIAE​(java.lang.Throwable t)
      Method that will wrap 't' as an IllegalArgumentException if it is a checked exception; otherwise (runtime exception or error) throw as is
      static void throwAsIAE​(java.lang.Throwable t, java.lang.String msg)
      Method that will wrap 't' as an IllegalArgumentException (and with specified message) if it is a checked exception; otherwise (runtime exception or error) throw as is
      static <T> T throwAsMappingException​(DeserializationContext ctxt, java.io.IOException e0)  
      static java.lang.Throwable throwIfError​(java.lang.Throwable t)
      Helper method that will check if argument is an Error, and if so, (re)throw it; otherwise just return
      static java.lang.Throwable throwIfIOE​(java.lang.Throwable t)
      Helper method that will check if argument is an IOException, and if so, (re)throw it; otherwise just return
      static java.lang.Throwable throwIfRTE​(java.lang.Throwable t)
      Helper method that will check if argument is an RuntimeException, and if so, (re)throw it; otherwise just return
      static java.lang.Throwable throwRootCauseIfIOE​(java.lang.Throwable t)
      Method that works like by calling getRootCause(java.lang.Throwable) and then either throwing it (if instanceof IOException), or return.
      static void unwrapAndThrowAsIAE​(java.lang.Throwable t)
      Method that will locate the innermost exception for given Throwable; and then wrap it as an IllegalArgumentException if it is a checked exception; otherwise (runtime exception or error) throw as is
      static void unwrapAndThrowAsIAE​(java.lang.Throwable t, java.lang.String msg)
      Method that will locate the innermost exception for given Throwable; and then wrap it as an IllegalArgumentException if it is a checked exception; otherwise (runtime exception or error) throw as is
      static void verifyMustOverride​(java.lang.Class<?> expType, java.lang.Object instance, java.lang.String method)  
      static java.lang.Class<?> wrapperType​(java.lang.Class<?> primitiveType)
      Helper method for finding wrapper type for given primitive type (why isn't there one in JDK?).
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ClassUtil

        public ClassUtil()
    • Method Detail

      • emptyIterator

        public static <T> java.util.Iterator<T> emptyIterator()
        Since:
        2.7
      • findSuperTypes

        public static java.util.List<JavaType> findSuperTypes​(JavaType type,
                                                              java.lang.Class<?> endBefore,
                                                              boolean addClassItself)
        Method that will find all sub-classes and implemented interfaces of a given class or interface. Classes are listed in order of precedence, starting with the immediate super-class, followed by interfaces class directly declares to implemented, and then recursively followed by parent of super-class and so forth. Note that Object.class is not included in the list regardless of whether endBefore argument is defined or not.
        Parameters:
        endBefore - Super-type to NOT include in results, if any; when encountered, will be ignored (and no super types are checked).
        Since:
        2.7
      • findRawSuperTypes

        public static java.util.List<java.lang.Class<?>> findRawSuperTypes​(java.lang.Class<?> cls,
                                                                           java.lang.Class<?> endBefore,
                                                                           boolean addClassItself)
        Since:
        2.7
      • findSuperClasses

        public static java.util.List<java.lang.Class<?>> findSuperClasses​(java.lang.Class<?> cls,
                                                                          java.lang.Class<?> endBefore,
                                                                          boolean addClassItself)
        Method for finding all super classes (but not super interfaces) of given class, starting with the immediate super class and ending in the most distant one. Class itself is included if addClassItself is true.

        NOTE: mostly/only called to resolve mix-ins as that's where we do not care about fully-resolved types, just associated annotations.

        Since:
        2.7
      • findSuperTypes

        @Deprecated
        public static java.util.List<java.lang.Class<?>> findSuperTypes​(java.lang.Class<?> cls,
                                                                        java.lang.Class<?> endBefore)
        Deprecated.
      • findSuperTypes

        @Deprecated
        public static java.util.List<java.lang.Class<?>> findSuperTypes​(java.lang.Class<?> cls,
                                                                        java.lang.Class<?> endBefore,
                                                                        java.util.List<java.lang.Class<?>> result)
        Deprecated.
      • canBeABeanType

        public static java.lang.String canBeABeanType​(java.lang.Class<?> type)
        Returns:
        Null if class might be a bean; type String (that identifies why it's not a bean) if not
      • isLocalType

        public static java.lang.String isLocalType​(java.lang.Class<?> type,
                                                   boolean allowNonStatic)
      • getOuterClass

        public static java.lang.Class<?> getOuterClass​(java.lang.Class<?> type)
        Method for finding enclosing class for non-static inner classes
      • isProxyType

        public static boolean isProxyType​(java.lang.Class<?> type)
        Helper method used to weed out dynamic Proxy types; types that do not expose concrete method API that we could use to figure out automatic Bean (property) based serialization.
      • isConcrete

        public static boolean isConcrete​(java.lang.Class<?> type)
        Helper method that checks if given class is a concrete one; that is, not an interface or abstract class.
      • isConcrete

        public static boolean isConcrete​(java.lang.reflect.Member member)
      • isCollectionMapOrArray

        public static boolean isCollectionMapOrArray​(java.lang.Class<?> type)
      • isBogusClass

        public static boolean isBogusClass​(java.lang.Class<?> cls)
      • isRecordType

        public static boolean isRecordType​(java.lang.Class<?> cls)
        Helper method for detecting Java14-added new Record types
        Since:
        2.12
      • isObjectOrPrimitive

        public static boolean isObjectOrPrimitive​(java.lang.Class<?> cls)
        Since:
        2.7
      • hasClass

        public static boolean hasClass​(java.lang.Object inst,
                                       java.lang.Class<?> raw)
        Since:
        2.9
      • verifyMustOverride

        public static void verifyMustOverride​(java.lang.Class<?> expType,
                                              java.lang.Object instance,
                                              java.lang.String method)
        Since:
        2.9
      • hasGetterSignature

        @Deprecated
        public static boolean hasGetterSignature​(java.lang.reflect.Method m)
        Deprecated.
        Since 2.6 not used; may be removed before 3.x
      • throwIfError

        public static java.lang.Throwable throwIfError​(java.lang.Throwable t)
        Helper method that will check if argument is an Error, and if so, (re)throw it; otherwise just return
        Since:
        2.9
      • throwIfRTE

        public static java.lang.Throwable throwIfRTE​(java.lang.Throwable t)
        Helper method that will check if argument is an RuntimeException, and if so, (re)throw it; otherwise just return
        Since:
        2.9
      • throwIfIOE

        public static java.lang.Throwable throwIfIOE​(java.lang.Throwable t)
                                              throws java.io.IOException
        Helper method that will check if argument is an IOException, and if so, (re)throw it; otherwise just return
        Throws:
        java.io.IOException
        Since:
        2.9
      • getRootCause

        public static java.lang.Throwable getRootCause​(java.lang.Throwable t)
        Method that can be used to find the "root cause", innermost of chained (wrapped) exceptions.
      • throwRootCauseIfIOE

        public static java.lang.Throwable throwRootCauseIfIOE​(java.lang.Throwable t)
                                                       throws java.io.IOException
        Method that works like by calling getRootCause(java.lang.Throwable) and then either throwing it (if instanceof IOException), or return.
        Throws:
        java.io.IOException
        Since:
        2.8
      • throwAsIAE

        public static void throwAsIAE​(java.lang.Throwable t)
        Method that will wrap 't' as an IllegalArgumentException if it is a checked exception; otherwise (runtime exception or error) throw as is
      • throwAsIAE

        public static void throwAsIAE​(java.lang.Throwable t,
                                      java.lang.String msg)
        Method that will wrap 't' as an IllegalArgumentException (and with specified message) if it is a checked exception; otherwise (runtime exception or error) throw as is
      • unwrapAndThrowAsIAE

        public static void unwrapAndThrowAsIAE​(java.lang.Throwable t)
        Method that will locate the innermost exception for given Throwable; and then wrap it as an IllegalArgumentException if it is a checked exception; otherwise (runtime exception or error) throw as is
      • unwrapAndThrowAsIAE

        public static void unwrapAndThrowAsIAE​(java.lang.Throwable t,
                                               java.lang.String msg)
        Method that will locate the innermost exception for given Throwable; and then wrap it as an IllegalArgumentException if it is a checked exception; otherwise (runtime exception or error) throw as is
      • closeOnFailAndThrowAsIOE

        public static void closeOnFailAndThrowAsIOE​(JsonGenerator g,
                                                    java.lang.Exception fail)
                                             throws java.io.IOException
        Helper method that encapsulate logic in trying to close output generator in case of failure; useful mostly in forcing flush()ing as otherwise error conditions tend to be hard to diagnose. However, it is often the case that output state may be corrupt so we need to be prepared for secondary exception without masking original one.
        Throws:
        java.io.IOException
        Since:
        2.8
      • closeOnFailAndThrowAsIOE

        public static void closeOnFailAndThrowAsIOE​(JsonGenerator g,
                                                    java.io.Closeable toClose,
                                                    java.lang.Exception fail)
                                             throws java.io.IOException
        Helper method that encapsulate logic in trying to close given Closeable in case of failure; useful mostly in forcing flush()ing as otherwise error conditions tend to be hard to diagnose. However, it is often the case that output state may be corrupt so we need to be prepared for secondary exception without masking original one.
        Throws:
        java.io.IOException
        Since:
        2.8
      • createInstance

        public static <T> T createInstance​(java.lang.Class<T> cls,
                                           boolean canFixAccess)
                                    throws java.lang.IllegalArgumentException
        Method that can be called to try to create an instantiate of specified type. Instantiation is done using default no-argument constructor.
        Parameters:
        canFixAccess - Whether it is possible to try to change access rights of the default constructor (in case it is not publicly accessible) or not.
        Throws:
        java.lang.IllegalArgumentException - If instantiation fails for any reason; except for cases where constructor throws an unchecked exception (which will be passed as is)
      • findConstructor

        public static <T> java.lang.reflect.Constructor<T> findConstructor​(java.lang.Class<T> cls,
                                                                           boolean forceAccess)
                                                                    throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException
      • classOf

        public static java.lang.Class<?> classOf​(java.lang.Object inst)
        Since:
        2.9
      • rawClass

        public static java.lang.Class<?> rawClass​(JavaType t)
        Since:
        2.9
      • nonNull

        public static <T> T nonNull​(T valueOrNull,
                                    T defaultValue)
        Since:
        2.9
      • nullOrToString

        public static java.lang.String nullOrToString​(java.lang.Object value)
        Since:
        2.9
      • nonNullString

        public static java.lang.String nonNullString​(java.lang.String str)
        Since:
        2.9
      • quotedOr

        public static java.lang.String quotedOr​(java.lang.Object str,
                                                java.lang.String forNull)
        Returns either quoted value (with double-quotes) -- if argument non-null String -- or String NULL (no quotes) (if null).
        Since:
        2.9
      • getClassDescription

        public static java.lang.String getClassDescription​(java.lang.Object classOrInstance)
        Helper method used to construct appropriate description when passed either type (Class) or an instance; in latter case, class of instance is to be used.
      • getTypeDescription

        public static java.lang.String getTypeDescription​(JavaType fullType)
        Helper method to create and return "backticked" description of given resolved type (or, "null" if null passed), similar to return vaue of getClassDescription(Object).
        Parameters:
        fullType - Fully resolved type or null
        Returns:
        String description of type including generic type parameters, surrounded by backticks, if type passed; or string "null" if {code null} passed
        Since:
        2.10
      • classNameOf

        public static java.lang.String classNameOf​(java.lang.Object inst)
        Helper method used to construct appropriate description when passed either type (Class) or an instance; in latter case, class of instance is to be used.
        Since:
        2.9
      • nameOf

        public static java.lang.String nameOf​(java.lang.Class<?> cls)
        Returns either `cls.getName()` (if `cls` not null), or "[null]" if `cls` is null.
        Since:
        2.9
      • nameOf

        public static java.lang.String nameOf​(Named named)
        Returns either single-quoted (apostrophe) 'named.getName()' (if named not null), or "[null]" if named is null.

        NOTE: before 2.12 returned "backticked" version instead of single-quoted name; changed to be compatible with most existing quoting usage within databind

        Since:
        2.9
      • name

        public static java.lang.String name​(java.lang.String name)
        Returns either single-quoted (apostrophe) 'name' (if name not null), or "[null]" if name is null.
        Since:
        2.12
      • name

        public static java.lang.String name​(PropertyName name)
        Returns either single-quoted (apostrophe) 'name' (if name not null), or "[null]" if name is null.
        Since:
        2.12
      • backticked

        public static java.lang.String backticked​(java.lang.String text)
        Returns either `text` (backtick-quoted) or [null].
        Since:
        2.9
      • apostrophed

        public static java.lang.String apostrophed​(java.lang.String text)
        Returns either 'text' (single-quoted) or [null].
        Since:
        2.9
      • exceptionMessage

        public static java.lang.String exceptionMessage​(java.lang.Throwable t)
        Helper method that returns Throwable.getMessage() for all other exceptions except for (a) JacksonException, for which getOriginalMessage() is returned, and (b) InvocationTargetException, for which the cause's message is returned, if available. Method is used to avoid accidentally including trailing location information twice in message when wrapping exceptions.
        Since:
        2.9.7
      • defaultValue

        public static java.lang.Object defaultValue​(java.lang.Class<?> cls)
        Helper method used to get default value for wrappers used for primitive types (0 for Integer etc)
      • wrapperType

        public static java.lang.Class<?> wrapperType​(java.lang.Class<?> primitiveType)
        Helper method for finding wrapper type for given primitive type (why isn't there one in JDK?). NOTE: throws IllegalArgumentException if given type is NOT primitive type (caller has to check).
      • primitiveType

        public static java.lang.Class<?> primitiveType​(java.lang.Class<?> type)
        Method that can be used to find primitive type for given class if (but only if) it is either wrapper type or primitive type; returns null if type is neither.
        Since:
        2.7
      • checkAndFixAccess

        @Deprecated
        public static void checkAndFixAccess​(java.lang.reflect.Member member)
        Deprecated.
        Since 2.7 call variant that takes boolean flag.
        Equivalent to call:
           checkAndFixAccess(member, false);
        
      • checkAndFixAccess

        public static void checkAndFixAccess​(java.lang.reflect.Member member,
                                             boolean evenIfAlreadyPublic)
        Method that is called if a Member may need forced access, to force a field, method or constructor to be accessible: this is done by calling AccessibleObject.setAccessible(boolean).
        Parameters:
        member - Accessor to call setAccessible() on.
        evenIfAlreadyPublic - Whether to always try to make accessor accessible, even if public (true), or only if needed to force by-pass of non-public access (false)
        Since:
        2.7
      • isEnumType

        public static boolean isEnumType​(java.lang.Class<?> rawType)
        Helper method that encapsulates reliable check on whether given raw type "is an Enum", that is, is or extends Enum.
        Since:
        2.10.1
      • findEnumType

        public static java.lang.Class<? extends java.lang.Enum<?>> findEnumType​(java.util.EnumSet<?> s)
        Helper method that can be used to dynamically figure out enumeration type of given EnumSet, without having access to its declaration. Code is needed to work around design flaw in JDK.
      • findEnumType

        public static java.lang.Class<? extends java.lang.Enum<?>> findEnumType​(java.util.EnumMap<?,​?> m)
        Helper method that can be used to dynamically figure out enumeration type of given EnumSet, without having access to its declaration. Code is needed to work around design flaw in JDK.
      • findEnumType

        public static java.lang.Class<? extends java.lang.Enum<?>> findEnumType​(java.lang.Enum<?> en)
        Helper method that can be used to dynamically figure out formal enumeration type (class) for given enumeration. This is either class of enum instance (for "simple" enumerations), or its superclass (for enums with instance fields or methods)
      • findEnumType

        public static java.lang.Class<? extends java.lang.Enum<?>> findEnumType​(java.lang.Class<?> cls)
        Helper method that can be used to dynamically figure out formal enumeration type (class) for given class of an enumeration value. This is either class of enum instance (for "simple" enumerations), or its superclass (for enums with instance fields or methods)
      • findFirstAnnotatedEnumValue

        public static <T extends java.lang.annotation.Annotation> java.lang.Enum<?> findFirstAnnotatedEnumValue​(java.lang.Class<java.lang.Enum<?>> enumClass,
                                                                                                                java.lang.Class<T> annotationClass)
        A method that will look for the first Enum value annotated with the given Annotation.

        If there's more than one value annotated, the first one found will be returned. Which one exactly is used is undetermined.

        Parameters:
        enumClass - The Enum class to scan for a value with the given annotation
        annotationClass - The annotation to look for.
        Returns:
        the Enum value annotated with the given Annotation or null if none is found.
        Throws:
        java.lang.IllegalArgumentException - if there's a reflection issue accessing the Enum
        Since:
        2.8
      • isJacksonStdImpl

        public static boolean isJacksonStdImpl​(java.lang.Object impl)
        Method that can be called to determine if given Object is the default implementation Jackson uses; as opposed to a custom serializer installed by a module or calling application. Determination is done using JacksonStdImpl annotation on handler (serializer, deserializer etc) class.

        NOTE: passing `null` is legal, and will result in true being returned.

      • isJacksonStdImpl

        public static boolean isJacksonStdImpl​(java.lang.Class<?> implClass)
      • isJDKClass

        public static boolean isJDKClass​(java.lang.Class<?> rawType)
        Accessor for checking whether given Class is under Java package of java.* or javax.* (including all sub-packages).

        Added since some aspects of handling need to be changed for JDK types (and possibly some extensions under javax.?): for example, forcing of access will not work well for future JDKs (12 and later).

        Note: in Jackson 2.11 only returned true for java.* (and not javax.*); was changed in 2.12.

        Since:
        2.11
      • isNonStaticInnerClass

        public static boolean isNonStaticInnerClass​(java.lang.Class<?> cls)
      • getPackageName

        @Deprecated
        public static java.lang.String getPackageName​(java.lang.Class<?> cls)
        Deprecated.
        Since 2.12 (just call methods directly or check class name)
        Since:
        2.7
      • hasEnclosingMethod

        public static boolean hasEnclosingMethod​(java.lang.Class<?> cls)
        Since:
        2.7
      • getDeclaredFields

        @Deprecated
        public static java.lang.reflect.Field[] getDeclaredFields​(java.lang.Class<?> cls)
        Deprecated.
        since 2.11 (just call Class method directly)
      • getDeclaredMethods

        @Deprecated
        public static java.lang.reflect.Method[] getDeclaredMethods​(java.lang.Class<?> cls)
        Deprecated.
        since 2.11 (just call Class method directly)
      • findClassAnnotations

        public static java.lang.annotation.Annotation[] findClassAnnotations​(java.lang.Class<?> cls)
        Since:
        2.7
      • getClassMethods

        public static java.lang.reflect.Method[] getClassMethods​(java.lang.Class<?> cls)
        Helper method that gets methods declared in given class; usually a simple thing, but sometimes (as per [databind#785]) more complicated, depending on classloader setup.
        Since:
        2.9
      • getConstructors

        public static ClassUtil.Ctor[] getConstructors​(java.lang.Class<?> cls)
        Since:
        2.7
      • getDeclaringClass

        public static java.lang.Class<?> getDeclaringClass​(java.lang.Class<?> cls)
        Since:
        2.7
      • getGenericSuperclass

        public static java.lang.reflect.Type getGenericSuperclass​(java.lang.Class<?> cls)
        Since:
        2.7
      • getGenericInterfaces

        public static java.lang.reflect.Type[] getGenericInterfaces​(java.lang.Class<?> cls)
        Since:
        2.7
      • getEnclosingClass

        public static java.lang.Class<?> getEnclosingClass​(java.lang.Class<?> cls)
        Since:
        2.7