Class ReflectionHelper

java.lang.Object
com.google.gson.internal.reflect.ReflectionHelper

public class ReflectionHelper extends Object
  • Field Details

  • Constructor Details

    • ReflectionHelper

      private ReflectionHelper()
  • Method Details

    • getInaccessibleTroubleshootingSuffix

      private static String getInaccessibleTroubleshootingSuffix(Exception e)
    • makeAccessible

      public static void makeAccessible(AccessibleObject object) throws JsonIOException
      Internal implementation of making an AccessibleObject accessible.
      Parameters:
      object - the object that AccessibleObject.setAccessible(boolean) should be called on.
      Throws:
      JsonIOException - if making the object accessible fails
    • getAccessibleObjectDescription

      public static String getAccessibleObjectDescription(AccessibleObject object, boolean uppercaseFirstLetter)
      Returns a short string describing the AccessibleObject in a human-readable way. The result is normally shorter than Object.toString() because it omits modifiers (e.g. final) and uses simple names for constructor and method parameter types.
      Parameters:
      object - object to describe
      uppercaseFirstLetter - whether the first letter of the description should be uppercased
    • fieldToString

      public static String fieldToString(Field field)
      Creates a string representation for a field, omitting modifiers and the field type.
    • constructorToString

      public static String constructorToString(Constructor<?> constructor)
      Creates a string representation for a constructor. E.g.: java.lang.String(char[], int, int)
    • appendExecutableParameters

      private static void appendExecutableParameters(AccessibleObject executable, StringBuilder stringBuilder)
    • isStatic

      public static boolean isStatic(Class<?> clazz)
    • isAnonymousOrNonStaticLocal

      public static boolean isAnonymousOrNonStaticLocal(Class<?> clazz)
      Returns whether the class is anonymous or a non-static local class.
    • tryMakeAccessible

      public static String tryMakeAccessible(Constructor<?> constructor)
      Tries making the constructor accessible, returning an exception message if this fails.
      Parameters:
      constructor - constructor to make accessible
      Returns:
      exception message; null if successful, non-null if unsuccessful
    • isRecord

      public static boolean isRecord(Class<?> raw)
      If records are supported on the JVM, this is equivalent to a call to Class.isRecord()
    • getRecordComponentNames

      public static String[] getRecordComponentNames(Class<?> raw)
    • getAccessor

      public static Method getAccessor(Class<?> raw, Field field)
      Looks up the record accessor method that corresponds to the given record field
    • getCanonicalRecordConstructor

      public static <T> Constructor<T> getCanonicalRecordConstructor(Class<T> raw)
    • createExceptionForUnexpectedIllegalAccess

      public static RuntimeException createExceptionForUnexpectedIllegalAccess(IllegalAccessException exception)
    • createExceptionForRecordReflectionException

      private static RuntimeException createExceptionForRecordReflectionException(ReflectiveOperationException exception)