Top Inners Fields Constructors Methods
com.fasterxml.jackson.databind.util

public final Class ClassUtil

extends Object
Class Inheritance
Imports
java.io.Closeable, .IOException, java.lang.annotation.Annotation, java.lang.reflect.*, java.util.*, com.fasterxml.jackson.core.JacksonException, .JsonGenerator, com.fasterxml.jackson.databind.DeserializationContext, .JavaType, .JsonMappingException, .PropertyName, com.fasterxml.jackson.databind.annotation.JacksonStdImpl

Nested and Inner Type Summary

Modifier and TypeClass and Description
public 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.

private static class
ClassUtil.EnumTypeLocator

Inner class used to contain gory details of how we can determine details of instances of common JDK types like EnumMaps.

Field Summary

Modifier and TypeField and Description
private static final Class<?>
private static final Iterator<?>
private static final Annotation[]
private static final ClassUtil.Ctor[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static void
_addRawSuperTypes(Class<?> cls, Class<?> endBefore, Collection<Class<?>> result, boolean addClassItself)

private static void
_addSuperTypes(JavaType type, Class<?> endBefore, Collection<JavaType> result, boolean addClassItself)

private static Method[]
private static Class<?>[]
public static String
apostrophed(String text)

Returns either 'text' (single-quoted) or [null].

public static String
backticked(String text)

Returns either `text` (backtick-quoted) or [null].

public static String

Returns:

Null if class might be a bean; type String (that identifies why it's not a bean) if not
canBeABeanType
(Class<?> type)

public static void
checkAndFixAccess(Member member)

Deprecated Since 2.7 call variant that takes boolean flag.
Equivalent to call:
   checkAndFixAccess(member, false);
public static void
checkAndFixAccess(Member
Accessor to call setAccessible() on.
member
,
boolean
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)
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).

public static String
classNameOf(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.

public static Class<?>
public static void
closeOnFailAndThrowAsIOE(JsonGenerator g, 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.

public static void
closeOnFailAndThrowAsIOE(JsonGenerator g, Closeable toClose, 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.

public static <T> T
createInstance(Class<T> cls, boolean
Whether it is possible to try to change access rights of the default constructor (in case it is not publicly accessible) or not.
canFixAccess
)

Method that can be called to try to create an instantiate of specified type.

public static Object
defaultValue(Class<?> cls)

Helper method used to get default value for wrappers used for primitive types (0 for Integer etc)

public static <T> Iterator<T>
public static String
exceptionMessage(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.

public static Annotation[]
public static <T> Constructor<T>
findConstructor(Class<T> cls, boolean forceAccess)

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.

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.

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.

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.

public static <T extends Annotation> Enum<?>

Returns:

the Enum value annotated with the given Annotation or null if none is found.
findFirstAnnotatedEnumValue
(Class<Enum<?>>
The Enum class to scan for a value with the given annotation
enumClass
,
Class<T>
The annotation to look for.
annotationClass
)

A method that will look for the first Enum value annotated with the given Annotation.

public static List<Class<?>>
findRawSuperTypes(Class<?> cls, Class<?> endBefore, boolean addClassItself)

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.

public static List<JavaType>
findSuperTypes(JavaType type, Class<?>
Super-type to NOT include in results, if any; when encountered, will be ignored (and no super types are checked).
endBefore
,
boolean addClassItself)

Method that will find all sub-classes and implemented interfaces of a given class or interface.

public static List<Class<?>>
findSuperTypes(Class<?> cls, Class<?> endBefore)

Deprecated
public static List<Class<?>>
findSuperTypes(Class<?> cls, Class<?> endBefore, List<Class<?>> result)

Deprecated
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.

public static Method[]
getClassMethods(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.

public static ClassUtil.Ctor[]
public static Field[]
getDeclaredFields(Class<?> cls)

Deprecated since 2.11 (just call Class method directly)
public static Method[]
getDeclaredMethods(Class<?> cls)

Deprecated since 2.11 (just call Class method directly)
public static Class<?>
public static Class<?>
public static Type[]
public static Type
public static int

Returns:

Major version of JDK we are running on
getJDKMajorVersion
()

public static Class<?>
getOuterClass(Class<?> type)

Method for finding enclosing class for non-static inner classes

public static String
getPackageName(Class<?> cls)

Deprecated Since 2.12 (just call methods directly or check class name)
public static Throwable
getRootCause(Throwable t)

Method that can be used to find the "root cause", innermost of chained (wrapped) exceptions.

public static String

Returns:

String description of type including generic type parameters, surrounded by backticks, if type passed; or string "null" if {code null} passed
getTypeDescription
(JavaType
Fully resolved type or null
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).

public static boolean
hasClass(Object inst, Class<?> raw)

public static boolean
public static boolean
hasGetterSignature(Method m)

Deprecated Since 2.6 not used; may be removed before 3.x
public static boolean
public static boolean
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.

public static boolean
public static boolean
isEnumType(Class<?> rawType)

Helper method that encapsulates reliable check on whether given raw type "is an Enum", that is, is or extends java.lang.Enum.

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.

public static boolean
isJacksonStdImpl(Class<?> implClass)

public static boolean

Returns:

True if we can determine that the code is running on JDK 17 or above; false otherwise.
isJDK17OrAbove
()

Convenience method for:

   return getJDKMajorVersion() >= 17
public static boolean
isJDKClass(Class<?> rawType)

Accessor for checking whether given Class is under Java package of java.* or javax.* (including all sub-packages).

public static String
isLocalType(Class<?> type, boolean allowNonStatic)

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

public static boolean
isRecordType(Class<?> cls)

Helper method for detecting Java14-added new Record types

public static String
name(String name)

Returns either single-quoted (apostrophe) 'name' (if name not null), or "[null]" if name is null.

public static String
name(PropertyName name)

Returns either single-quoted (apostrophe) 'name' (if name not null), or "[null]" if name is null.

public static String
nameOf(Class<?> cls)

Returns either `cls.getName()` (if `cls` not null), or "[null]" if `cls` is null.

public static String
nameOf(Named named)

Returns either single-quoted (apostrophe) 'named.getName()' (if named not null), or "[null]" if named is null.

public static <T> T
nonNull(T valueOrNull, T defaultValue)

public static String
public static String
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.

public static String
quotedOr(Object str, String forNull)

Returns either quoted value (with double-quotes) -- if argument non-null String -- or String NULL (no quotes) (if null).

public static Class<?>
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

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

public static <T> T
public static Throwable
throwIfError(Throwable t)

Helper method that will check if argument is an Error, and if so, (re)throw it; otherwise just return

public static Throwable
throwIfIOE(Throwable t)

Helper method that will check if argument is an IOException, and if so, (re)throw it; otherwise just return

public static Throwable
throwIfRTE(Throwable t)

Helper method that will check if argument is an RuntimeException, and if so, (re)throw it; otherwise just return

public static Throwable
throwRootCauseIfIOE(Throwable t)

Method that works like by calling getRootCause and then either throwing it (if instanceof IOException), or return.

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

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

public static void
verifyMustOverride(Class<?> expType, Object instance, String method)

public static Class<?>
wrapperType(Class<?> primitiveType)

Helper method for finding wrapper type for given primitive type (why isn't there one in JDK?).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait