Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.fasterxml.jackson.databind;
import java.lang.reflect.Modifier;
import com.fasterxml.jackson.core.type.ResolvedType;
import com.fasterxml.jackson.databind.type.TypeFactory;
/**
* 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 {@link java.lang.reflect.Type} to allow
* it to be pushed through interfaces that only expose that type.
*/
public abstract class JavaType
extends ResolvedType
implements java.io.Serializable, // 2.1
java.lang.reflect.Type // 2.2
{
private static final long serialVersionUID = 1;
/**
* 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.
*/
protected final Class _class;
protected final int _hash;
/**
* 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.
*/
protected final Object _valueHandler;
/**
* 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.
*/
protected final Object _typeHandler;
/**
* Whether entities defined with this type should be handled using
* static typing (as opposed to dynamic runtime type) or not.
*
* @since 2.2
*/
protected final boolean _asStatic;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
/**
* @param raw "Raw" (type-erased) class for this type
* @param additionalHash Additional hash code to use, in addition
* to hash code of the class name
*/
protected JavaType(Class raw, int additionalHash,
Object valueHandler, Object typeHandler, boolean asStatic)
{
_class = raw;
_hash = raw.getName().hashCode() + additionalHash;
_valueHandler = valueHandler;
_typeHandler = typeHandler;
_asStatic = asStatic;
}
/**
* "Copy method" that will construct a new instance that is identical to
* this instance, except that it will have specified type handler assigned.
*
* @return Newly created type instance
*/
public abstract JavaType withTypeHandler(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.
*
* @return Newly created type instance
*/
public abstract JavaType withContentTypeHandler(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.
*
* @return Newly created type instance
*/
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 content value handler assigned.
*
* @return Newly created type instance
*/
public abstract JavaType withContentValueHandler(Object h);
/**
* 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
*/
public abstract JavaType withStaticTyping();
/*
/**********************************************************
/* Type coercion fluent factory methods
/**********************************************************
*/
/**
* 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
* {@link IllegalArgumentException} is thrown.
* If class is same as the current raw class, instance itself is
* returned.
*/
public JavaType narrowBy(Class subclass)
{
// First: if same raw class, just return this instance
if (subclass == _class) { return this; }
// Otherwise, ensure compatibility
_assertSubclass(subclass, _class);
JavaType result = _narrow(subclass);
// TODO: these checks should NOT actually be needed; above should suffice:
if (_valueHandler != result.