Top Description Fields Constructors Methods
com.fasterxml.jackson.core.type

public abstract Class TypeReference<T>

extends Object
implements Comparable<TypeReference<T>>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Imports
java.lang.reflect.ParameterizedType, .Type

This generic abstract class is used for obtaining full generics type information by sub-classing; it must be converted to ResolvedType implementation (implemented by JavaType from "databind" bundle) to be used. Class is based on ideas from http://gafter.blogspot.com/2006/12/super-type-tokens.html, Additional idea (from a suggestion made in comments of the article) is to require bogus implementation of Comparable (any such generic interface would do, as long as it forces a method with generic type to be implemented). to ensure that a Type argument is indeed given.

Usage is by sub-classing: here is one way to instantiate reference to generic type List<Integer>:

  TypeReference ref = new TypeReference<List<Integer>>() { };
which can be passed to methods that accept TypeReference, or resolved using TypeFactory to obtain ResolvedType.

Field Summary

Modifier and TypeField and Description
protected final Type

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(TypeReference<T>
the object to be compared.
o
)

Implements java.lang.Comparable.compareTo.

The only reason we define this method (and require implementation of Comparable) is to prevent constructing a reference without type information.

public Type
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_typeback to summary
protected final Type _type

Constructor Detail

TypeReferenceback to summary
protected TypeReference()

Method Detail

compareToback to summary
public int compareTo(TypeReference<T> o)

Implements java.lang.Comparable.compareTo.

The only reason we define this method (and require implementation of Comparable) is to prevent constructing a reference without type information.

Parameters
o:TypeReference<T>

Doc from java.lang.Comparable.compareTo.

the object to be compared.

Returns:int

Doc from java.lang.Comparable.compareTo.

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
getTypeback to summary
public Type getType()