Class TypeBindings
- java.lang.Object
-
- com.fasterxml.jackson.databind.type.TypeBindings
-
- All Implemented Interfaces:
java.io.Serializable
public class TypeBindings extends java.lang.Object implements java.io.SerializableHelper class used for resolving type parameters for given class- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classTypeBindings.AsKeyHelper type used to allow caching of generic types(package private) static classTypeBindings.TypeParamStashHelper class that contains simple logic for avoiding repeated lookups viaClass.getTypeParameters()as that can be a performance issue for some use cases (wasteful, usually one-off or not reusing mapper).
-
Field Summary
Fields Modifier and Type Field Description private int_hashCodeprivate java.lang.String[]_namesArray of type (type variable) names.private JavaType[]_typesTypes matching namesprivate java.lang.String[]_unboundVariablesNames of potentially unresolved type variables.private static TypeBindingsEMPTYprivate static java.lang.String[]NO_STRINGSprivate static JavaType[]NO_TYPESprivate static longserialVersionUID
-
Constructor Summary
Constructors Modifier Constructor Description privateTypeBindings(java.lang.String[] names, JavaType[] types, java.lang.String[] uvars)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ObjectasKey(java.lang.Class<?> rawBase)Factory method that will create an object that can be used as a key for caching purposes byTypeFactorystatic TypeBindingscreate(java.lang.Class<?> erasedType, JavaType typeArg1)static TypeBindingscreate(java.lang.Class<?> erasedType, JavaType[] types)static TypeBindingscreate(java.lang.Class<?> erasedType, JavaType typeArg1, JavaType typeArg2)static TypeBindingscreate(java.lang.Class<?> erasedType, java.util.List<JavaType> typeList)Factory method for constructing bindings for given class using specified type parameters.static TypeBindingscreate(java.util.List<java.lang.String> names, java.util.List<JavaType> types)Factory method for constructing bindings given names and associated types.static TypeBindingscreateIfNeeded(java.lang.Class<?> erasedType, JavaType typeArg1)Alternate factory method that may be called if it is possible that type does or does not require type parameters; this is mostly useful for collection- and map-like types.static TypeBindingscreateIfNeeded(java.lang.Class<?> erasedType, JavaType[] types)Alternate factory method that may be called if it is possible that type does or does not require type parameters; this is mostly useful for collection- and map-like types.static TypeBindingsemptyBindings()booleanequals(java.lang.Object o)JavaTypefindBoundType(java.lang.String name)Find type bound to specified name, if there is one; returns bound type if so, null if not.java.lang.StringgetBoundName(int index)JavaTypegetBoundType(int index)Get the type bound to the variable atindex.JavaTypegetBoundTypeOrNull(int index)Get the type bound to the variable atindex.java.util.List<JavaType>getTypeParameters()Accessor for getting bound types in declaration orderinthashCode()booleanhasUnbound(java.lang.String name)private booleaninvalidCacheKey()Returns true if a shallow search of the type bindings includes a placeholder type which uses reference equality, thus cannot produce cache hits.booleanisEmpty()protected java.lang.ObjectreadResolve()intsize()Returns number of bindings containedjava.lang.StringtoString()protected JavaType[]typeParameterArray()TypeBindingswithoutVariable(java.lang.String name)Create a new instance with the same bindings as this object, except with the given variable removed.TypeBindingswithUnboundVariable(java.lang.String name)Method for creating an instance that has same bindings as this object, plus an indicator for additional type variable that may be unbound within this context; this is needed to resolve recursive self-references.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
NO_STRINGS
private static final java.lang.String[] NO_STRINGS
-
NO_TYPES
private static final JavaType[] NO_TYPES
-
EMPTY
private static final TypeBindings EMPTY
-
_names
private final java.lang.String[] _names
Array of type (type variable) names.
-
_types
private final JavaType[] _types
Types matching names
-
_unboundVariables
private final java.lang.String[] _unboundVariables
Names of potentially unresolved type variables.- Since:
- 2.3
-
_hashCode
private final int _hashCode
-
-
Constructor Detail
-
TypeBindings
private TypeBindings(java.lang.String[] names, JavaType[] types, java.lang.String[] uvars)
-
-
Method Detail
-
emptyBindings
public static TypeBindings emptyBindings()
-
readResolve
protected java.lang.Object readResolve()
-
create
public static TypeBindings create(java.lang.Class<?> erasedType, java.util.List<JavaType> typeList)
Factory method for constructing bindings for given class using specified type parameters.
-
create
public static TypeBindings create(java.lang.Class<?> erasedType, JavaType[] types)
-
create
public static TypeBindings create(java.lang.Class<?> erasedType, JavaType typeArg1)
-
create
public static TypeBindings create(java.lang.Class<?> erasedType, JavaType typeArg1, JavaType typeArg2)
-
create
public static TypeBindings create(java.util.List<java.lang.String> names, java.util.List<JavaType> types)
Factory method for constructing bindings given names and associated types.
-
createIfNeeded
public static TypeBindings createIfNeeded(java.lang.Class<?> erasedType, JavaType typeArg1)
Alternate factory method that may be called if it is possible that type does or does not require type parameters; this is mostly useful for collection- and map-like types.
-
createIfNeeded
public static TypeBindings createIfNeeded(java.lang.Class<?> erasedType, JavaType[] types)
Alternate factory method that may be called if it is possible that type does or does not require type parameters; this is mostly useful for collection- and map-like types.
-
withUnboundVariable
public TypeBindings withUnboundVariable(java.lang.String name)
Method for creating an instance that has same bindings as this object, plus an indicator for additional type variable that may be unbound within this context; this is needed to resolve recursive self-references.
-
withoutVariable
public TypeBindings withoutVariable(java.lang.String name)
Create a new instance with the same bindings as this object, except with the given variable removed. This is used to create generic types that are "partially raw", i.e. only have some variables bound.- Since:
- 2.16
-
findBoundType
public JavaType findBoundType(java.lang.String name)
Find type bound to specified name, if there is one; returns bound type if so, null if not.
-
invalidCacheKey
private boolean invalidCacheKey()
Returns true if a shallow search of the type bindings includes a placeholder type which uses reference equality, thus cannot produce cache hits. This is an optimization to avoid churning memory in the cache unnecessarily. Note that it is still possible for nested type information to contain such placeholder types (see NestedTypes1604Test for an example) so it's vital that they produce a distribution of hashCode values, even if they may push reusable data out of the cache.
-
isEmpty
public boolean isEmpty()
-
size
public int size()
Returns number of bindings contained
-
getBoundName
public java.lang.String getBoundName(int index)
-
getBoundType
public JavaType getBoundType(int index)
Get the type bound to the variable atindex. If the type isnot boundbut the index is withinsize()constraints, this method returnsTypeFactory.unknownType()for compatibility. If the index is out ofsize()constraints, this method will still returnnull.
-
getBoundTypeOrNull
public JavaType getBoundTypeOrNull(int index)
Get the type bound to the variable atindex. If the type isnot boundor the index is withinsize()constraints, this method returnsnull.- Since:
- 2.16
-
getTypeParameters
public java.util.List<JavaType> getTypeParameters()
Accessor for getting bound types in declaration order
-
hasUnbound
public boolean hasUnbound(java.lang.String name)
- Since:
- 2.3
-
asKey
public java.lang.Object asKey(java.lang.Class<?> rawBase)
Factory method that will create an object that can be used as a key for caching purposes byTypeFactory- Returns:
- An object which can be used as a key in TypeFactory, or
nullif no key can be created. - Since:
- 2.8
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
typeParameterArray
protected JavaType[] typeParameterArray()
-
-