com.fasterxml.jackson.databind

## Class JavaType

- java.lang.Object
- - com.fasterxml.jackson.core.type.ResolvedType
  - - com.fasterxml.jackson.databind.JavaType

- All Implemented Interfaces:
    Serializable, Type
  Direct Known Subclasses:
    TypeBase

      public abstract class JavaType
      extends com.fasterxml.jackson.core.type.ResolvedType
      implements Serializable, Type

  Base class for type token classes used both to contain information and as keys for deserializers.

  Instances can (only) be constructed by `com.fasterxml.jackson.databind.type.TypeFactory`.

  Since 2.2 this implements `Type` to allow it to be pushed through interfaces that only expose that type.

  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `_asStatic` Whether entities defined with this type should be handled using static typing (as opposed to dynamic runtime type) or not.
    `protected Class<?>` | `_class` This is the nominal type-erased Class that would be close to the type represented (but not exactly type, due to type erasure: type instance may have more information on this).
    `protected int` | `_hash`
    `protected Object` | `_typeHandler` Optional handler that can be attached to indicate how to handle additional type metadata associated with this type.
    `protected Object` | `_valueHandler` Optional handler (codec) that can be attached to indicate what to use for handling (serializing, deserializing) values of this specific type.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `JavaType(Class<?> raw, int additionalHash, Object valueHandler, Object typeHandler, boolean asStatic)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `_assertSubclass(Class<?> subclass, Class<?> superClass)`
    `protected abstract JavaType` | `_narrow(Class<?> subclass)`
    `protected JavaType` | `_widen(Class<?> superclass)` Default implementation is just to call `_narrow(java.lang.Class<?>)`, since underlying type construction is usually identical
    `JavaType` | `containedType(int index)`
    `int` | `containedTypeCount()`
    `String` | `containedTypeName(int index)`
    `JavaType` | `containedTypeOrUnknown(int index)` Convenience method that is functionally same as: `JavaType t = containedType(index); if (t == null) { t = TypeFactory.unknownType(); }` and typically used to eliminate need for null checks for common case where we just want to check if containedType is available first; and if not, use "unknown type" (which translates to `java.lang.Object` basically).
    `abstract boolean` | `equals(Object o)`
    `JavaType` | `forcedNarrowBy(Class<?> subclass)` More efficient version of `narrowBy(java.lang.Class<?>)`, called by internal framework in cases where compatibility checks are to be skipped.
    `JavaType` | `getContentType()`
    `String` | `getErasedSignature()` Method for accessing signature without generic type information, in form compatible with all versions of JVM, and specifically used for type descriptions when generating byte code.
    `abstract StringBuilder` | `getErasedSignature(StringBuilder sb)` Method for accessing signature without generic type information, in form compatible with all versions of JVM, and specifically used for type descriptions when generating byte code.
    `String` | `getGenericSignature()` Method for accessing signature that contains generic type information, in form compatible with JVM 1.5 as per JLS.
    `abstract StringBuilder` | `getGenericSignature(StringBuilder sb)`
    `JavaType` | `getKeyType()`
    `abstract Class<?>` | `getParameterSource()`
    `Class<?>` | `getRawClass()`
    `<T> T` | `getTypeHandler()` Method for accessing type handler associated with this type, if any
    `<T> T` | `getValueHandler()` Method for accessing value handler associated with this type, if any
    `boolean` | `hasGenericTypes()`
    `int` | `hashCode()`
    `boolean` | `hasRawClass(Class<?> clz)` Method that can be used to check whether this type has specified Class as its type erasure.
    `boolean` | `isAbstract()`
    `boolean` | `isArrayType()`
    `boolean` | `isCollectionLikeType()`
    `boolean` | `isConcrete()` Convenience method for checking whether underlying Java type is a concrete class or not: abstract classes and interfaces are not.
    `abstract boolean` | `isContainerType()`
    `boolean` | `isEnumType()`
    `boolean` | `isFinal()`
    `boolean` | `isInterface()`
    `boolean` | `isMapLikeType()`
    `boolean` | `isPrimitive()`
    `boolean` | `isThrowable()`
    `JavaType` | `narrowBy(Class<?> subclass)` Method that can be called to do a "narrowing" conversions; that is, to return a type with a raw class that is assignable to the raw class of this type.
    `abstract JavaType` | `narrowContentsBy(Class<?> contentClass)`
    `abstract String` | `toString()`
    `boolean` | `useStaticType()` Accessor for checking whether handlers for dealing with values of this type should use static typing (as opposed to dynamic typing).
    `JavaType` | `widenBy(Class<?> superclass)` Method that can be called to do a "widening" conversions; that is, to return a type with a raw class that could be assigned from this type.
    `abstract JavaType` | `widenContentsBy(Class<?> contentClass)`
    `abstract JavaType` | `withContentTypeHandler(Object h)` "Copy method" that will construct a new instance that is identical to this instance, except that its content type will have specified type handler assigned.
    `abstract JavaType` | `withContentValueHandler(Object h)` "Copy method" that will construct a new instance that is identical to this instance, except that it will have specified content value handler assigned.
    `abstract JavaType` | `withStaticTyping()` Method that can be called to get a type instance that indicates that values of the type should be handled using "static typing" for purposes of serialization (as opposed to "dynamic" aka runtime typing): meaning that no runtime information is needed for determining serializers to use.
    `abstract JavaType` | `withTypeHandler(Object h)` "Copy method" that will construct a new instance that is identical to this instance, except that it will have specified type handler assigned.
    `abstract JavaType` | `withValueHandler(Object h)` "Copy method" that will construct a new instance that is identical to this instance, except that it will have specified value handler assigned.

    - ### Methods inherited from class com.fasterxml.jackson.core.type.ResolvedType

      `toCanonical`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### _class

          protected final Class<?> _class

      This is the nominal type-erased Class that would be close to the type represented (but not exactly type, due to type erasure: type instance may have more information on this). May be an interface or abstract class, so instantiation may not be possible.

    - #### _hash

          protected final int _hash

    - #### _valueHandler

          protected final Object _valueHandler

      Optional handler (codec) that can be attached to indicate what to use for handling (serializing, deserializing) values of this specific type.

      Note: untyped (i.e. caller has to cast) because it is used for different kinds of handlers, with unrelated types.

    - #### _typeHandler

          protected final Object _typeHandler

      Optional handler that can be attached to indicate how to handle additional type metadata associated with this type.

      Note: untyped (i.e. caller has to cast) because it is used for different kinds of handlers, with unrelated types.

    - #### _asStatic

          protected final boolean _asStatic

      Whether entities defined with this type should be handled using static typing (as opposed to dynamic runtime type) or not.
      Since:
        2.2

  - ### Constructor Detail

    - #### JavaType

          protected JavaType(Class<?> raw,
                  int additionalHash,
                  Object valueHandler,
                  Object typeHandler,
                  boolean asStatic)

      Parameters:
        `raw` - "Raw" (type-erased) class for this type
        `additionalHash` - Additional hash code to use, in addition to hash code of the class name

  - ### Method Detail

    - #### withTypeHandler

          public abstract JavaType withTypeHandler(Object h)

      "Copy method" that will construct a new instance that is identical to this instance, except that it will have specified type handler assigned.
      Returns:
        Newly created type instance

    - #### withContentTypeHandler

          public abstract JavaType withContentTypeHandler(Object h)

      "Copy method" that will construct a new instance that is identical to this instance, except that its content type will have specified type handler assigned.
      Returns:
        Newly created type instance

    - #### withValueHandler

          public abstract JavaType withValueHandler(Object h)

      "Copy method" that will construct a new instance that is identical to this instance, except that it will have specified value handler assigned.
      Returns:
        Newly created type instance

    - #### withContentValueHandler

          public abstract JavaType withContentValueHandler(Object h)

      "Copy method" that will construct a new instance that is identical to this instance, except that it will have specified content value handler assigned.
      Returns:
        Newly created type instance

    - #### withStaticTyping

          public abstract JavaType withStaticTyping()

      Method that can be called to get a type instance that indicates that values of the type should be handled using "static typing" for purposes of serialization (as opposed to "dynamic" aka runtime typing): meaning that no runtime information is needed for determining serializers to use. The main use case is to allow forcing of specific root value serialization type, and specifically in resolving serializers for contained types (element types for arrays, Collections and Maps).
      Since:
        2.2

    - #### narrowBy

          public JavaType narrowBy(Class<?> subclass)

      Method that can be called to do a "narrowing" conversions; that is, to return a type with a raw class that is assignable to the raw class of this type. If this is not possible, an `IllegalArgumentException` is thrown. If class is same as the current raw class, instance itself is returned.

    - #### forcedNarrowBy

          public JavaType forcedNarrowBy(Class<?> subclass)

      More efficient version of `narrowBy(java.lang.Class<?>)`, called by internal framework in cases where compatibility checks are to be skipped.

    - #### widenBy

          public JavaType widenBy(Class<?> superclass)

      Method that can be called to do a "widening" conversions; that is, to return a type with a raw class that could be assigned from this type. If such conversion is not possible, an `IllegalArgumentException` is thrown. If class is same as the current raw class, instance itself is returned.

    - #### _narrow

          protected abstract JavaType _narrow(Class<?> subclass)

    - #### _widen

          protected JavaType _widen(Class<?> superclass)

      Default implementation is just to call `_narrow(java.lang.Class<?>)`, since underlying type construction is usually identical

    - #### narrowContentsBy

          public abstract JavaType narrowContentsBy(Class<?> contentClass)

    - #### widenContentsBy

          public abstract JavaType widenContentsBy(Class<?> contentClass)

    - #### getRawClass

          public final Class<?> getRawClass()

      Specified by:
        `getRawClass` in class `com.fasterxml.jackson.core.type.ResolvedType`

    - #### hasRawClass

          public final boolean hasRawClass(Class<?> clz)

      Method that can be used to check whether this type has specified Class as its type erasure. Put another way, returns true if instantiation of this Type is given (type-erased) Class.
      Specified by:
        `hasRawClass` in class `com.fasterxml.jackson.core.type.ResolvedType`

    - #### isAbstract

          public boolean isAbstract()

      Specified by:
        `isAbstract` in class `com.fasterxml.jackson.core.type.ResolvedType`

    - #### isConcrete

          public boolean isConcrete()

      Convenience method for checking whether underlying Java type is a concrete class or not: abstract classes and interfaces are not.
      Specified by:
        `isConcrete` in class `com.fasterxml.jackson.core.type.ResolvedType`

    - #### isThrowable

          public boolean isThrowable()

      Specified by:
        `isThrowable` in class `com.fasterxml.jackson.core.type.ResolvedType`

    - #### isArrayType

          public boolean isArrayType()

      Specified by:
        `isArrayType` in class `com.fasterxml.jackson.core.type.ResolvedType`

    - #### isEnumType

          public final boolean isEnumType()

      Specified by:
        `isEnumType` in class `com.fasterxml.jackson.core.type.ResolvedType`

    - #### isInterface

          public final boolean isInterface()

      Specified by:
        `isInterface` in class `com.fasterxml.jackson.core.type.ResolvedType`

    - #### isPrimitive

          public final boolean isPrimitive()

      Specified by:
        `isPrimitive` in class `com.fasterxml.jackson.core.type.ResolvedType`

    - #### isFinal

          public final boolean isFinal()

      Specified by:
        `isFinal` in class `com.fasterxml.jackson.core.type.ResolvedType`

    - #### isContainerType

          public abstract boolean isContainerType()

      Specified by:
        `isContainerType` in class `com.fasterxml.jackson.core.type.ResolvedType`
      Returns:
        True if type represented is a container type; this includes array, Map and Collection types.

    - #### isCollectionLikeType

          public boolean isCollectionLikeType()

      Specified by:
        `isCollectionLikeType` in class `com.fasterxml.jackson.core.type.ResolvedType`
      Returns:
        True if type is either true `Collection` type, or something similar (meaning it has at least one type parameter, which describes type of contents)

    - #### isMapLikeType

          public boolean isMapLikeType()

      Specified by:
        `isMapLikeType` in class `com.fasterxml.jackson.core.type.ResolvedType`
      Returns:
        True if type is either true `Map` type, or something similar (meaning it has at least two type parameter; first one describing key type, second value type)

    - #### useStaticType

          public final boolean useStaticType()

      Accessor for checking whether handlers for dealing with values of this type should use static typing (as opposed to dynamic typing). Note that while value of 'true' does mean that static typing is to be used, value of 'false' may still be overridden by other settings.
      Since:
        2.2

    - #### hasGenericTypes

          public boolean hasGenericTypes()

      Specified by:
        `hasGenericTypes` in class `com.fasterxml.jackson.core.type.ResolvedType`

    - #### getKeyType

          public JavaType getKeyType()

      Specified by:
        `getKeyType` in class `com.fasterxml.jackson.core.type.ResolvedType`

    - #### getContentType

          public JavaType getContentType()

      Specified by:
        `getContentType` in class `com.fasterxml.jackson.core.type.ResolvedType`

    - #### containedTypeCount

          public int containedTypeCount()

      Specified by:
        `containedTypeCount` in class `com.fasterxml.jackson.core.type.ResolvedType`

    - #### containedType

          public JavaType containedType(int index)

      Specified by:
        `containedType` in class `com.fasterxml.jackson.core.type.ResolvedType`

    - #### containedTypeName

          public String containedTypeName(int index)

      Specified by:
        `containedTypeName` in class `com.fasterxml.jackson.core.type.ResolvedType`

    - #### getParameterSource

          public abstract Class<?> getParameterSource()

      Overrides:
        `getParameterSource` in class `com.fasterxml.jackson.core.type.ResolvedType`

    - #### containedTypeOrUnknown

          public JavaType containedTypeOrUnknown(int index)

      Convenience method that is functionally same as: `JavaType t = containedType(index); if (t == null) { t = TypeFactory.unknownType(); }` and typically used to eliminate need for null checks for common case where we just want to check if containedType is available first; and if not, use "unknown type" (which translates to `java.lang.Object` basically).
      Since:
        2.5

    - #### getValueHandler

          public <T> T getValueHandler()

      Method for accessing value handler associated with this type, if any

    - #### getTypeHandler

          public <T> T getTypeHandler()

      Method for accessing type handler associated with this type, if any

    - #### getGenericSignature

          public String getGenericSignature()

      Method for accessing signature that contains generic type information, in form compatible with JVM 1.5 as per JLS. It is a superset of `getErasedSignature()`, in that generic information can be automatically removed if necessary (just remove outermost angle brackets along with content inside)

    - #### getGenericSignature

          public abstract StringBuilder getGenericSignature(StringBuilder sb)

      Parameters:
        `sb` - StringBuilder to append signature to
      Returns:
        StringBuilder that was passed in; returned to allow call chaining

    - #### getErasedSignature

          public String getErasedSignature()

      Method for accessing signature without generic type information, in form compatible with all versions of JVM, and specifically used for type descriptions when generating byte code.

    - #### getErasedSignature

          public abstract StringBuilder getErasedSignature(StringBuilder sb)

      Method for accessing signature without generic type information, in form compatible with all versions of JVM, and specifically used for type descriptions when generating byte code.
      Parameters:
        `sb` - StringBuilder to append signature to
      Returns:
        StringBuilder that was passed in; returned to allow call chaining

    - #### _assertSubclass

          protected void _assertSubclass(Class<?> subclass,
                             Class<?> superClass)

    - #### toString

          public abstract String toString()

      Overrides:
        `toString` in class `Object`

    - #### equals

          public abstract boolean equals(Object o)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public final int hashCode()

      Overrides:
        `hashCode` in class `Object`

Copyright © 2014-2015 FasterXML. All Rights Reserved.