com.fasterxml.jackson.databind.util

Class ClassUtil



  • public final class ClassUtil
    extends Object
    • Constructor Detail

      • ClassUtil

        public ClassUtil()
    • Method Detail

      • emptyIterator

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

        public static List<JavaType> findSuperTypes(JavaType type,
                                    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 List<Class<?>> findRawSuperTypes(Class<?> cls,
                                       Class<?> endBefore,
                                       boolean addClassItself)
        Since:
        2.7
      • findSuperClasses

        public static List<Class<?>> findSuperClasses(Class<?> cls,
                                      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.
        Since:
        2.7
      • canBeABeanType

        public static String canBeABeanType(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 String isLocalType(Class<?> type,
                         boolean allowNonStatic)
      • getOuterClass

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

        public static boolean isProxyType(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(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(Member member)
      • isCollectionMapOrArray

        public static boolean isCollectionMapOrArray(Class<?> type)
      • getClassDescription

        public static String getClassDescription(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.
      • getPackageName

        public static String getPackageName(Class<?> cls)
        Since:
        2.7
      • hasEnclosingMethod

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

        public static Field[] getDeclaredFields(Class<?> cls)
        Since:
        2.7
      • getDeclaredMethods

        public static Method[] getDeclaredMethods(Class<?> cls)
        Since:
        2.7
      • findClassAnnotations

        public static Annotation[] findClassAnnotations(Class<?> cls)
        Since:
        2.7
      • getDeclaringClass

        public static Class<?> getDeclaringClass(Class<?> cls)
        Since:
        2.7
      • getGenericSuperclass

        public static Type getGenericSuperclass(Class<?> cls)
        Since:
        2.7
      • getGenericInterfaces

        public static Type[] getGenericInterfaces(Class<?> cls)
        Since:
        2.7
      • getEnclosingClass

        public static Class<?> getEnclosingClass(Class<?> cls)
        Since:
        2.7
      • hasGetterSignature

        @Deprecated
        public static boolean hasGetterSignature(Method m)
        Deprecated. Since 2.6 not used; may be removed before 3.x
      • getRootCause

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

        public static void throwRootCause(Throwable t)
                                   throws Exception
        Method that will unwrap root causes of given Throwable, and throw the innermost Exception or Error as is. This is useful in cases where mandatory wrapping is added, which is often done by Reflection API.
        Throws:
        Exception
      • throwAsIAE

        public static void throwAsIAE(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(Throwable t,
                      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(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(Throwable t,
                               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
      • createInstance

        public static <T> T createInstance(Class<T> cls,
                           boolean canFixAccess)
                                throws 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:
        IllegalArgumentException - If instantiation fails for any reason; except for cases where constructor throws an unchecked exception (which will be passed as is)
      • defaultValue

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

        public static Class<?> wrapperType(Class<?> primitiveType)
        Helper method for finding wrapper type for given primitive type (why isn't there one in JDK?)
      • primitiveType

        public static Class<?> primitiveType(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(Member member)
        Deprecated. Since 2.7 call variant that takes boolean flag.
        Equivalent to call:
           checkAndFixAccess(member, false);
        
      • checkAndFixAccess

        public static void checkAndFixAccess(Member member,
                             boolean force)
        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.
        force - Whether to always try to make accessor accessible (true), or only if needed as per access rights (false)
        Since:
        2.7
      • findEnumType

        public static Class<? extends Enum<?>> findEnumType(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 Class<? extends Enum<?>> findEnumType(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 Class<? extends Enum<?>> findEnumType(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 Class<? extends Enum<?>> findEnumType(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)
      • isJacksonStdImpl

        public static boolean isJacksonStdImpl(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.
      • isJacksonStdImpl

        public static boolean isJacksonStdImpl(Class<?> implClass)
      • isBogusClass

        public static boolean isBogusClass(Class<?> cls)
      • isNonStaticInnerClass

        public static boolean isNonStaticInnerClass(Class<?> cls)
      • isObjectOrPrimitive

        public static boolean isObjectOrPrimitive(Class<?> cls)
        Since:
        2.7

Copyright © 2008–2016 FasterXML. All rights reserved.