|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.jackson.map.type.TypeFactory
public class TypeFactory
Class used for constracting concrete JavaType
instances,
given various inputs.
Typical usage patterns is to statically import factory methods
of this class, to allow convenient instantiation of structured
types, especially Collection
and Map
types
to represent generic types. For example
mapType(String.class, Integer.class)to represent
Map<String,Integer>This is an alternative to using
TypeReference
that would
be something like
new TypeReference<Map<String,Integer>>() { }
Field Summary | |
---|---|
protected TypeParser |
_parser
|
static TypeFactory |
instance
|
Method Summary | ||
---|---|---|
protected static SimpleType |
_constructSimple(Class<?> rawType,
JavaType[] parameterTypes)
|
|
protected
|
_findParentType(Class<?> clz,
Class<T> expType)
Method that is to figure out actual type parameters that given class binds to generic types defined by given interface type. |
|
protected JavaType |
_fromArrayType(GenericArrayType type,
TypeBindings context)
|
|
protected JavaType |
_fromClass(Class<?> clz,
TypeBindings context)
|
|
protected JavaType |
_fromParameterizedClass(Class<?> clz,
List<JavaType> paramTypes)
Method used by TypeParser when generics-aware version
is constructed. |
|
protected JavaType |
_fromParamType(ParameterizedType type,
TypeBindings context)
This method deals with parameterized types, that is, first class generic classes. |
|
JavaType |
_fromType(Type type,
TypeBindings context)
Factory method that can be used if type information is passed as Java typing returned from getGenericXxx methods
(usually for a return or argument type). |
|
protected JavaType |
_fromVariable(TypeVariable<?> type,
TypeBindings context)
|
|
protected JavaType |
_fromWildcard(WildcardType type,
TypeBindings context)
|
|
protected JavaType |
_unknownType()
|
|
static JavaType |
arrayType(Class<?> elementType)
Convenience factory method for constructing JavaType that
represent array that contains elements
of specified type. |
|
static JavaType |
arrayType(JavaType elementType)
Convenience factory method for constructing JavaType that
represent array that contains elements
of specified type. |
|
static JavaType |
collectionType(Class<? extends Collection> collectionType,
Class<?> elementType)
Convenience factory method for constructing JavaType that
represent Collection of specified type and contains elements
of specified type |
|
static JavaType |
collectionType(Class<? extends Collection> collectionType,
JavaType elementType)
Convenience factory method for constructing JavaType that
represent Collection of specified type and contains elements
of specified type |
|
static JavaType |
fromCanonical(String canonical)
Factory method for constructing a JavaType out of its canonical
representation (see JavaType.toCanonical() ). |
|
static JavaType |
fromClass(Class<?> clz)
Deprecated. Use type(Type) instead |
|
static JavaType |
fromType(Type type)
Deprecated. Use type(Type) instead |
|
static JavaType |
fromTypeReference(TypeReference<?> ref)
Deprecated. Use type(Type) instead |
|
static JavaType |
mapType(Class<? extends Map> mapType,
Class<?> keyType,
Class<?> valueType)
Convenience factory method for constructing JavaType that
represent Map of specified type and contains elements
of specified type |
|
static JavaType |
mapType(Class<? extends Map> mapType,
JavaType keyType,
JavaType valueType)
Convenience factory method for constructing JavaType that
represent Map of specified type and contains elements
of specified type |
|
static JavaType |
parametricType(Class<?> parametrized,
Class<?>... parameterClasses)
Factory method for constructing JavaType that
represents a parameterized type. |
|
static JavaType |
parametricType(Class<?> parametrized,
JavaType... parameterTypes)
Factory method for constructing JavaType that
represents a parameterized type. |
|
static JavaType |
specialize(JavaType baseType,
Class<?> subclass)
Method that tries to create specialized type given base type, and a sub-class thereof (which is assumed to use same parametrization as supertype). |
|
static JavaType |
type(Type t)
Factory method for constructing JavaType from given
"raw" type; which may be anything from simple Class
to full generic type. |
|
static JavaType |
type(Type type,
Class<?> context)
Factory method that can use given context to resolve named generic types. |
|
static JavaType |
type(TypeReference<?> ref)
Factory method that can be used if the full generic type has been passed using TypeReference . |
|
static JavaType |
type(Type type,
TypeBindings bindings)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final TypeFactory instance
protected final TypeParser _parser
Method Detail |
---|
public static JavaType type(Type t)
JavaType
from given
"raw" type; which may be anything from simple Class
to full generic type.
public static JavaType type(Type type, Class<?> context)
context
- Class used for resolving generic types; for example,
for bean properties the actual bean class (not necessarily class
that contains method or field, may be a sub-class thereof)public static JavaType type(Type type, TypeBindings bindings)
public static JavaType type(TypeReference<?> ref)
TypeReference
. This only needs to be
done if the root type to bind to is generic; but if so,
it must be done to get proper typing.
public static JavaType arrayType(Class<?> elementType)
JavaType
that
represent array that contains elements
of specified type.
public static JavaType arrayType(JavaType elementType)
JavaType
that
represent array that contains elements
of specified type.
public static JavaType collectionType(Class<? extends Collection> collectionType, Class<?> elementType)
JavaType
that
represent Collection of specified type and contains elements
of specified type
public static JavaType collectionType(Class<? extends Collection> collectionType, JavaType elementType)
JavaType
that
represent Collection of specified type and contains elements
of specified type
public static JavaType mapType(Class<? extends Map> mapType, Class<?> keyType, Class<?> valueType)
JavaType
that
represent Map of specified type and contains elements
of specified type
public static JavaType mapType(Class<? extends Map> mapType, JavaType keyType, JavaType valueType)
JavaType
that
represent Map of specified type and contains elements
of specified type
public static JavaType parametricType(Class<?> parametrized, Class<?>... parameterClasses)
JavaType
that
represents a parameterized type. For example, to represent
type Iterator<String>
, you could
call
TypeFactory.parametricType(Iterator.class, String.class)
public static JavaType parametricType(Class<?> parametrized, JavaType... parameterTypes)
JavaType
that
represents a parameterized type. For example, to represent
type List<Set<Integer>>
, you could
call
JavaType inner = TypeFactory.parametricType(Set.class, Integer.class); TypeFactory.parametricType(List.class, inner);
public static JavaType fromCanonical(String canonical) throws IllegalArgumentException
JavaType
out of its canonical
representation (see JavaType.toCanonical()
).
canonical
- Canonical string representation of a type
IllegalArgumentException
- If canonical representation is malformed,
or class that type represents (including its generic parameters) is
not foundpublic static JavaType specialize(JavaType baseType, Class<?> subclass)
JavaType.narrowBy(Class)
,
but can change underlying JavaType
(from simple to Map, for
example), unliked narrowBy
which assumes same logical
type.
public static JavaType fromClass(Class<?> clz)
type(Type)
instead
Class
. This means that there
will not be generic type information due to type erasure,
but at least it will be possible to recognize array
types and non-typed container types.
And for other types (primitives/wrappers, beans), this
is all that is needed.
public static JavaType fromTypeReference(TypeReference<?> ref)
type(Type)
instead
TypeReference
. This only needs to be
done if the root type to bind to is generic; but if so,
it must be done to get proper typing.
public static JavaType fromType(Type type)
type(Type)
instead
getGenericXxx
methods
(usually for a return or argument type).
protected JavaType _fromClass(Class<?> clz, TypeBindings context)
genericParams
- Mapping of formal parameter declarations (for generic
types) into actual typesprotected JavaType _fromParameterizedClass(Class<?> clz, List<JavaType> paramTypes)
TypeParser
when generics-aware version
is constructed.
public JavaType _fromType(Type type, TypeBindings context)
getGenericXxx
methods
(usually for a return or argument type).
protected JavaType _fromParamType(ParameterizedType type, TypeBindings context)
Since version 1.2, this resolves all parameterized types, not just Maps or Collections.
protected static SimpleType _constructSimple(Class<?> rawType, JavaType[] parameterTypes)
protected JavaType _fromArrayType(GenericArrayType type, TypeBindings context)
protected JavaType _fromVariable(TypeVariable<?> type, TypeBindings context)
protected JavaType _fromWildcard(WildcardType type, TypeBindings context)
protected <T extends JavaType> T _findParentType(Class<?> clz, Class<T> expType)
protected JavaType _unknownType()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |