org.codehaus.jackson.map.type
Class TypeFactory

java.lang.Object
  extended by org.codehaus.jackson.map.type.TypeFactory

public class TypeFactory
extends Object

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(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
static TypeFactory instance
           
 
Method Summary
protected
<T extends JavaType>
T
_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, JavaType context)
           
protected  JavaType _fromClass(Class<?> clz, Map<String,JavaType> genericParams)
           
protected  JavaType _fromParamType(ParameterizedType type, JavaType context)
          This method deals with parameterized types, that is, first class generic classes.
 JavaType _fromType(Type type, JavaType 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, JavaType context)
           
protected  JavaType _fromWildcard(WildcardType type, JavaType 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 fromClass(Class<?> clz)
          Deprecated. Use type(Type) instead
static JavaType fromType(Type type)
          Deprecated. Use type(Type) instead
static JavaType fromType(Type type, JavaType context)
          Deprecated. Use type(Type,JavaType) 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 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, JavaType 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

public static final TypeFactory instance
Method Detail

type

public 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.

Since:
1.3

type

public static JavaType type(Type type,
                            JavaType context)
Factory method that can use given context to resolve named generic types.

Parameters:
context - Type context that can be used for binding named formal type parameters, if any (if null, no context is used)

type

public static JavaType type(TypeReference<?> ref)
Factory method that can be used if the full generic type has been passed using 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.


arrayType

public static JavaType arrayType(Class<?> elementType)
Convenience factory method for constructing JavaType that represent array that contains elements of specified type.

Since:
1.3

arrayType

public static JavaType arrayType(JavaType elementType)
Convenience factory method for constructing JavaType that represent array that contains elements of specified type.

Since:
1.3

collectionType

public 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

Since:
1.3

collectionType

public 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

Since:
1.3

mapType

public 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

Since:
1.3

mapType

public 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

Since:
1.3

fromClass

public static JavaType fromClass(Class<?> clz)
Deprecated. Use type(Type) instead

Factory method that can be used if only type information available is of type 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.


fromTypeReference

public static JavaType fromTypeReference(TypeReference<?> ref)
Deprecated. Use type(Type) instead

Factory method that can be used if the full generic type has been passed using 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.


fromType

public static JavaType fromType(Type type)
Deprecated. Use type(Type) instead

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).


fromType

public static JavaType fromType(Type type,
                                JavaType context)
Deprecated. Use type(Type,JavaType) instead

Parameters:
context - Type context that can be used for binding named formal type parameters, if any (if null, no context is used)

_fromClass

protected JavaType _fromClass(Class<?> clz,
                              Map<String,JavaType> genericParams)
Parameters:
genericParams - Mapping of formal parameter declarations (for generic types) into actual types

_fromType

public JavaType _fromType(Type type,
                          JavaType 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).


_fromParamType

protected JavaType _fromParamType(ParameterizedType type,
                                  JavaType context)
This method deals with parameterized types, that is, first class generic classes.

Since version 1.2, this resolves all generics types, not just Maps or Collections.


_fromArrayType

protected JavaType _fromArrayType(GenericArrayType type,
                                  JavaType context)

_fromVariable

protected JavaType _fromVariable(TypeVariable<?> type,
                                 JavaType context)

_fromWildcard

protected JavaType _fromWildcard(WildcardType type,
                                 JavaType context)

_findParentType

protected <T extends JavaType> T _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. This could mean, for example, trying to figure out key and value types for Map implementations.


_unknownType

protected JavaType _unknownType()