public final class ClassUtil extends Object
Modifier and Type | Class and 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 and Description |
---|
ClassUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
canBeABeanType(Class<?> type) |
static void |
checkAndFixAccess(Member member)
Deprecated.
Since 2.7 call variant that takes boolean flag.
|
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) . |
static <T> T |
createInstance(Class<T> cls,
boolean canFixAccess)
Method that can be called to try to create an instantiate of
specified type.
|
static Object |
defaultValue(Class<?> cls)
Helper method used to get default value for wrappers used for primitive types
(0 for Integer etc)
|
static <T> Iterator<T> |
emptyIterator() |
static Class<?> |
findClass(String className)
Deprecated.
Since 2.6, use method in
TypeFactory . |
static Annotation[] |
findClassAnnotations(Class<?> cls) |
static <T> Constructor<T> |
findConstructor(Class<T> cls,
boolean canFixAccess) |
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.
|
static Class<? extends Enum<?>> |
findEnumType(Enum<?> en)
Helper method that can be used to dynamically figure out formal
enumeration type (class) for given enumeration.
|
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. |
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. |
static List<Class<?>> |
findRawSuperTypes(Class<?> cls,
Class<?> endBefore,
boolean addClassItself) |
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.
|
static List<Class<?>> |
findSuperTypes(Class<?> cls,
Class<?> endBefore)
Deprecated.
|
static List<Class<?>> |
findSuperTypes(Class<?> cls,
Class<?> endBefore,
List<Class<?>> result)
Deprecated.
|
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.
|
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.
|
static ClassUtil.Ctor[] |
getConstructors(Class<?> cls) |
static Field[] |
getDeclaredFields(Class<?> cls) |
static Method[] |
getDeclaredMethods(Class<?> cls) |
static Class<?> |
getDeclaringClass(Class<?> cls) |
static Class<?> |
getEnclosingClass(Class<?> cls) |
static Type[] |
getGenericInterfaces(Class<?> cls) |
static Type |
getGenericSuperclass(Class<?> cls) |
static Class<?> |
getOuterClass(Class<?> type)
Method for finding enclosing class for non-static inner classes
|
static String |
getPackageName(Class<?> cls) |
static Throwable |
getRootCause(Throwable t)
Method that can be used to find the "root cause", innermost
of chained (wrapped) exceptions.
|
static boolean |
hasEnclosingMethod(Class<?> cls) |
static boolean |
hasGetterSignature(Method m)
Deprecated.
Since 2.6 not used; may be removed before 3.x
|
static boolean |
isBogusClass(Class<?> cls) |
static boolean |
isCollectionMapOrArray(Class<?> type) |
static boolean |
isConcrete(Class<?> type)
Helper method that checks if given class is a concrete one;
that is, not an interface or abstract class.
|
static boolean |
isConcrete(Member member) |
static boolean |
isJacksonStdImpl(Class<?> implClass) |
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.
|
static String |
isLocalType(Class<?> type,
boolean allowNonStatic) |
static boolean |
isNonStaticInnerClass(Class<?> cls) |
static boolean |
isObjectOrPrimitive(Class<?> cls) |
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.
|
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.
|
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 |
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 |
static void |
throwRootCause(Throwable t)
|
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 |
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 |
static Class<?> |
wrapperType(Class<?> primitiveType)
Helper method for finding wrapper type for given primitive type (why isn't
there one in JDK?)
|
public static <T> Iterator<T> emptyIterator()
public static List<JavaType> findSuperTypes(JavaType type, Class<?> endBefore, boolean addClassItself)
Object.class
is not included in the list
regardless of whether endBefore
argument is defined or not.endBefore
- Super-type to NOT include in results, if any; when
encountered, will be ignored (and no super types are checked).public static List<Class<?>> findRawSuperTypes(Class<?> cls, Class<?> endBefore, boolean addClassItself)
public static List<Class<?>> findSuperClasses(Class<?> cls, Class<?> endBefore, boolean addClassItself)
addClassItself
is true.@Deprecated public static List<Class<?>> findSuperTypes(Class<?> cls, Class<?> endBefore)
@Deprecated public static List<Class<?>> findSuperTypes(Class<?> cls, Class<?> endBefore, List<Class<?>> result)
public static String canBeABeanType(Class<?> type)
public static Class<?> getOuterClass(Class<?> type)
public static boolean isProxyType(Class<?> type)
public static boolean isConcrete(Class<?> type)
public static boolean isConcrete(Member member)
public static boolean isCollectionMapOrArray(Class<?> type)
public static String getClassDescription(Object classOrInstance)
@Deprecated public static Class<?> findClass(String className) throws ClassNotFoundException
TypeFactory
.ClassNotFoundException
public static boolean hasEnclosingMethod(Class<?> cls)
public static Annotation[] findClassAnnotations(Class<?> cls)
public static ClassUtil.Ctor[] getConstructors(Class<?> cls)
@Deprecated public static boolean hasGetterSignature(Method m)
public static Throwable getRootCause(Throwable t)
public static void throwRootCause(Throwable t) throws Exception
Exception
or Error
as is.
This is useful in cases where mandatory wrapping is added, which
is often done by Reflection API.Exception
public static void throwAsIAE(Throwable t)
IllegalArgumentException
if it
is a checked exception; otherwise (runtime exception or error) throw as ispublic static void throwAsIAE(Throwable t, String msg)
IllegalArgumentException
(and with
specified message) if it
is a checked exception; otherwise (runtime exception or error) throw as ispublic static void unwrapAndThrowAsIAE(Throwable t)
IllegalArgumentException
if it
is a checked exception; otherwise (runtime exception or error) throw as ispublic static void unwrapAndThrowAsIAE(Throwable t, String msg)
IllegalArgumentException
if it
is a checked exception; otherwise (runtime exception or error) throw as ispublic static <T> T createInstance(Class<T> cls, boolean canFixAccess) throws IllegalArgumentException
canFixAccess
- Whether it is possible to try to change access
rights of the default constructor (in case it is not publicly
accessible) or not.IllegalArgumentException
- If instantiation fails for any reason;
except for cases where constructor throws an unchecked exception
(which will be passed as is)public static <T> Constructor<T> findConstructor(Class<T> cls, boolean canFixAccess) throws IllegalArgumentException
IllegalArgumentException
public static Object defaultValue(Class<?> cls)
public static Class<?> wrapperType(Class<?> primitiveType)
public static Class<?> primitiveType(Class<?> type)
@Deprecated public static void checkAndFixAccess(Member member)
checkAndFixAccess(member, false);
public static void checkAndFixAccess(Member member, boolean force)
Member
may need forced access,
to force a field, method or constructor to be accessible: this
is done by calling AccessibleObject.setAccessible(boolean)
.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)public static Class<? extends Enum<?>> findEnumType(EnumSet<?> s)
EnumSet
, without having
access to its declaration.
Code is needed to work around design flaw in JDK.public static Class<? extends Enum<?>> findEnumType(EnumMap<?,?> m)
EnumSet
, without having
access to its declaration.
Code is needed to work around design flaw in JDK.public static Class<? extends Enum<?>> findEnumType(Enum<?> en)
public static Class<? extends Enum<?>> findEnumType(Class<?> cls)
public static boolean isJacksonStdImpl(Object impl)
JacksonStdImpl
annotation on handler (serializer, deserializer etc)
class.public static boolean isJacksonStdImpl(Class<?> implClass)
public static boolean isBogusClass(Class<?> cls)
public static boolean isNonStaticInnerClass(Class<?> cls)
public static boolean isObjectOrPrimitive(Class<?> cls)
Copyright © 2008–2016 FasterXML. All rights reserved.