Package nonapi.io.github.classgraph.json
Class ClassFieldCache
- java.lang.Object
-
- nonapi.io.github.classgraph.json.ClassFieldCache
-
class ClassFieldCache extends java.lang.Object
A cache of field types and associated constructors for each encountered class, used to speed up constructor lookup.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ClassFieldCache.NoConstructor
Placeholder class to signify no constructor was found previously.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Class<?>,ClassFields>
classToClassFields
The map from class ref to class fields.private java.util.Map<java.lang.Class<?>,java.lang.reflect.Constructor<?>>
constructorForConcreteTypeWithSizeHint
The constructor with size hint for each concrete type.private java.util.Map<java.lang.Class<?>,java.lang.reflect.Constructor<?>>
defaultConstructorForConcreteType
The default constructor for each concrete type.private static java.lang.reflect.Constructor<?>
NO_CONSTRUCTOR
Placeholder constructor to signify no constructor was found previously.private boolean
onlySerializePublicFields
Whether or not to serialize public fields.(package private) ReflectionUtils
reflectionUtils
private boolean
resolveTypes
Whether or not to resolve types.
-
Constructor Summary
Constructors Constructor Description ClassFieldCache(boolean forDeserialization, boolean onlySerializePublicFields, ReflectionUtils reflectionUtils)
Create a class field cache.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) ClassFields
get(java.lang.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.private static java.lang.Class<?>
getConcreteType(java.lang.Class<?> rawType, boolean returnNullIfNotMapOrCollection)
Get the concrete type for a map or collection whose raw type is an interface or abstract class.(package private) java.lang.reflect.Constructor<?>
getConstructorWithSizeHintForConcreteTypeOf(java.lang.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).(package private) java.lang.reflect.Constructor<?>
getDefaultConstructorForConcreteTypeOf(java.lang.Class<?> cls)
Get the concrete type of the given class, then return the default constructor for that type.
-
-
-
Field Detail
-
classToClassFields
private final java.util.Map<java.lang.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 java.util.Map<java.lang.Class<?>,java.lang.reflect.Constructor<?>> defaultConstructorForConcreteType
The default constructor for each concrete type.
-
constructorForConcreteTypeWithSizeHint
private final java.util.Map<java.lang.Class<?>,java.lang.reflect.Constructor<?>> constructorForConcreteTypeWithSizeHint
The constructor with size hint for each concrete type.
-
NO_CONSTRUCTOR
private static final java.lang.reflect.Constructor<?> NO_CONSTRUCTOR
Placeholder constructor to signify no constructor was found previously.
-
reflectionUtils
ReflectionUtils reflectionUtils
-
-
Constructor Detail
-
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 Detail
-
get
ClassFields get(java.lang.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 java.lang.Class<?> getConcreteType(java.lang.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 typereturnNullIfNotMapOrCollection
- return null if not map or collection- Returns:
- the concrete type
-
getDefaultConstructorForConcreteTypeOf
java.lang.reflect.Constructor<?> getDefaultConstructorForConcreteTypeOf(java.lang.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:
java.lang.IllegalArgumentException
- if no default constructor is both found and accessible.
-
getConstructorWithSizeHintForConcreteTypeOf
java.lang.reflect.Constructor<?> getConstructorWithSizeHintForConcreteTypeOf(java.lang.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
-
-