Class ClassFieldCache

java.lang.Object
nonapi.io.github.classgraph.json.ClassFieldCache

class ClassFieldCache extends Object
A cache of field types and associated constructors for each encountered class, used to speed up constructor lookup.
  • Field Details

    • classToClassFields

      private final Map<Class<?>,ClassFields> classToClassFields
      The map from class ref to class fields.
    • resolveTypes

      private final boolean resolveTypes
      Whether or not to resolve types.
    • onlySerializePublicFields

      private final boolean onlySerializePublicFields
      Whether or not to serialize public fields.
    • defaultConstructorForConcreteType

      private final Map<Class<?>,Constructor<?>> defaultConstructorForConcreteType
      The default constructor for each concrete type.
    • constructorForConcreteTypeWithSizeHint

      private final Map<Class<?>,Constructor<?>> constructorForConcreteTypeWithSizeHint
      The constructor with size hint for each concrete type.
    • NO_CONSTRUCTOR

      private static final Constructor<?> NO_CONSTRUCTOR
      Placeholder constructor to signify no constructor was found previously.
    • reflectionUtils

      ReflectionUtils reflectionUtils
  • Constructor Details

    • ClassFieldCache

      ClassFieldCache(boolean forDeserialization, boolean onlySerializePublicFields, ReflectionUtils reflectionUtils)
      Create a class field cache.
      Parameters:
      forDeserialization - Set this to true if the cache will be used for deserialization (or both serialization and deserialization), or false if just used for serialization (for speed).
      onlySerializePublicFields - Set this to true if you only want to serialize public fields (ignored for deserialization).
  • Method Details

    • get

      ClassFields get(Class<?> cls)
      For a given resolved type, find the visible and accessible fields, resolve the types of any generically typed fields, and return the resolved fields.
      Parameters:
      cls - the cls
      Returns:
      the class fields
    • getConcreteType

      private static Class<?> getConcreteType(Class<?> rawType, boolean returnNullIfNotMapOrCollection)
      Get the concrete type for a map or collection whose raw type is an interface or abstract class.
      Parameters:
      rawType - the raw type
      returnNullIfNotMapOrCollection - return null if not map or collection
      Returns:
      the concrete type
    • getDefaultConstructorForConcreteTypeOf

      Constructor<?> getDefaultConstructorForConcreteTypeOf(Class<?> cls)
      Get the concrete type of the given class, then return the default constructor for that type.
      Parameters:
      cls - the class
      Returns:
      the default constructor for concrete type of class
      Throws:
      IllegalArgumentException - if no default constructor is both found and accessible.
    • getConstructorWithSizeHintForConcreteTypeOf

      Constructor<?> getConstructorWithSizeHintForConcreteTypeOf(Class<?> cls)
      Get the concrete type of the given class, then return the constructor for that type that takes a single integer parameter (the initial size hint, for Collection or Map). Returns null if not a Collection or Map, or there is no constructor with size hint.
      Parameters:
      cls - the class
      Returns:
      the constructor with size hint for concrete type of class