Package nonapi.io.github.classgraph.json
Class ClassFieldCache
java.lang.Object
nonapi.io.github.classgraph.json.ClassFieldCache
A cache of field types and associated constructors for each encountered class, used to speed up constructor
lookup.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Placeholder class to signify no constructor was found previously. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map
<Class<?>, ClassFields> The map from class ref to class fields.private final Map
<Class<?>, Constructor<?>> The constructor with size hint for each concrete type.private final Map
<Class<?>, Constructor<?>> The default constructor for each concrete type.private static final Constructor
<?> Placeholder constructor to signify no constructor was found previously.private final boolean
Whether or not to serialize public fields.(package private) ReflectionUtils
private final boolean
Whether or not to resolve types. -
Constructor Summary
ConstructorsConstructorDescriptionClassFieldCache
(boolean forDeserialization, boolean onlySerializePublicFields, ReflectionUtils reflectionUtils) Create a class field cache. -
Method Summary
Modifier and TypeMethodDescription(package private) ClassFields
For a given resolved type, find the visible and accessible fields, resolve the types of any generically typed fields, and return the resolved fields.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.(package private) Constructor
<?> 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).(package private) Constructor
<?> Get the concrete type of the given class, then return the default constructor for that type.
-
Field Details
-
classToClassFields
The map from class ref to class fields. -
resolveTypes
private final boolean resolveTypesWhether or not to resolve types. -
onlySerializePublicFields
private final boolean onlySerializePublicFieldsWhether or not to serialize public fields. -
defaultConstructorForConcreteType
The default constructor for each concrete type. -
constructorForConcreteTypeWithSizeHint
The constructor with size hint for each concrete type. -
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
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
Get the concrete type for a map or collection whose raw type is an interface or abstract class.- Parameters:
rawType
- the raw typereturnNullIfNotMapOrCollection
- return null if not map or collection- Returns:
- the concrete type
-
getDefaultConstructorForConcreteTypeOf
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
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
-