Class ReflectionUtils
java.lang.Object
org.eclipse.yasson.internal.ReflectionUtils
Utility class for resolution of generics during unmarshalling.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TcreateNoArgConstructorInstance(Constructor<T> constructor) Create instance with constructor.private static ParameterizedTypestatic ParameterizedTypefindParameterizedType(Class<?> classToSearch, Class<?> parameterizedInterface) For generic adapters like:static <T> Constructor<T> getDefaultConstructor(Class<T> clazz, boolean required) Get default no argument constructor of the class.private static Class<?> getMostSpecificBound(List<Type> chain, Class<?> result, Type bound, boolean warn) getOptionalRawType(Type type) Get raw type by type.static Class<?> getRawType(Type type) Get raw type by type.static booleanisResolvedType(Type type) Check if type needs resolution.static TyperesolveItemVariableType(List<Type> chain, TypeVariable<?> typeVariable, boolean warn) Resolve a bounded type variable type by its wrapper types.private static TyperesolveMostSpecificBound(List<Type> chain, WildcardType wildcardType, boolean warn) Resolves a wildcard most specific upper or lower bound.resolveOptionalType(List<Type> chain, Type type) Resolves type by item information and wraps it withOptional.static Class<?> resolveRawType(List<Type> chain, Type type) Get a raw type of any type.static TyperesolveType(List<Type> chain, Type type) Resolve a type by chain.private static TyperesolveType(List<Type> chain, Type type, boolean warn) static TyperesolveTypeArguments(ParameterizedType typeToResolve, Type typeToSearch) ResolvesTypeVariablearguments of generic types.
-
Field Details
-
LOGGER
-
-
Constructor Details
-
ReflectionUtils
private ReflectionUtils()
-
-
Method Details
-
getOptionalRawType
-
getRawType
-
resolveRawType
Get a raw type of any type. If type is aTypeVariablerecursively search type chain for resolution of typevar. If type is aWildcardTypefind most specific upper / lower bound, which can be used. If most specific bound is aTypeVariable, perform typevar resolution.- Parameters:
chain- hierarchy of all wrapping types.type- type to resolve, typically field type or generic bound, not null.- Returns:
- resolved raw class
-
resolveType
Resolve a type by chain. If type is aTypeVariablerecursively search type chain for resolution of typevar. If type is aWildcardTypefind most specific upper / lower bound, which can be used. If most specific bound is aTypeVariable, perform typevar resolution.- Parameters:
chain- hierarchy of all wrapping types.type- type to resolve, typically field type or generic bound, not null.- Returns:
- resolved type
-
resolveType
-
resolveOptionalType
-
resolveItemVariableType
public static Type resolveItemVariableType(List<Type> chain, TypeVariable<?> typeVariable, boolean warn) Resolve a bounded type variable type by its wrapper types. Resolution could be done only if a compile time generic information is provided, either: by generic field or subclass of a generic class.- Parameters:
chain- chain to search "runtime" generic type of a TypeVariable.typeVariable- type to search in chain for, not null.warn- whether or not to log a warning message when bounds are not found- Returns:
- Type of a generic "runtime" bound, not null.
-
resolveTypeArguments
ResolvesTypeVariablearguments of generic types.- Parameters:
typeToResolve- type to resolvetypeToSearch- type to search- Returns:
- resolved type
-
createNoArgConstructorInstance
Create instance with constructor.- Type Parameters:
T- type of instance- Parameters:
constructor- const not null- Returns:
- instance
-
getDefaultConstructor
Get default no argument constructor of the class.- Type Parameters:
T- Class generic type- Parameters:
clazz- Class to get constructor fromrequired- if true, throws an exception if the default constructor is missing. If false, returns null in that case- Returns:
- the constructor of the class, or null. Depending on required.
-
findParameterizedType
public static ParameterizedType findParameterizedType(Class<?> classToSearch, Class<?> parameterizedInterface) For generic adapters like:
We need to find a JsonbAdapter class which will hold basic generic type arguments, and resolve them if they are TypeVariables from there.interface ContainerAdapter<T> extends JsonbAdapter<Box<T>, Crate<T>>...; class IntegerBoxToCrateAdapter implements ContainerAdapter<Integer>...;- Parameters:
classToSearch- class to resolve parameterized interfaceparameterizedInterface- interface to search- Returns:
- type of JsonbAdapter
-
isResolvedType
Check if type needs resolution. If type is a class or a parametrized type with all type arguments as classes than it is considered resolved. If any of types is type variable or wildcard type is not resolved.- Parameters:
type- Type to check.- Returns:
- True if resolved
-
findParameterizedSuperclass
-
resolveMostSpecificBound
private static Type resolveMostSpecificBound(List<Type> chain, WildcardType wildcardType, boolean warn) Resolves a wildcard most specific upper or lower bound.- Parameters:
chain- Type.wildcardType- Wildcard type.- Returns:
- The most specific type.
-
getMostSpecificBound
-