Top Description Inners Fields Constructors Methods
com.google.gson.internal

public final Class ConstructorConstructor

extends Object
Class Inheritance
Imports
com.google.gson.InstanceCreator, .JsonIOException, .ReflectionAccessFilter, .ReflectionAccessFilter.FilterResult, com.google.gson.internal.reflect.ReflectionHelper, com.google.gson.reflect.TypeToken, java.lang.reflect.Constructor, .InvocationTargetException, .Modifier, .ParameterizedType, .Type, java.util.ArrayDeque, .ArrayList, .Collection, .EnumMap, .EnumSet, .LinkedHashMap, .LinkedHashSet, .List, .Map, .TreeMap, .TreeSet, java.util.concurrent.ConcurrentHashMap, .ConcurrentSkipListMap

Returns a function that can construct an instance of a requested type.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private final Map<Type, InstanceCreator<?>>
private final List<ReflectionAccessFilter>
private final boolean

Constructor Summary

AccessConstructor and Description
public
ConstructorConstructor(Map<Type, InstanceCreator<?>> instanceCreators, boolean useJdkUnsafe, List<ReflectionAccessFilter> reflectionFilters)

Method Summary

Modifier and TypeMethod and Description
pack-priv static String

Returns:

if instantiable null, else a non-null exception message
checkInstantiable
(Class<?>
instance of the class to be checked
c
)

Check if the class can be instantiated by Unsafe allocator.

public <T> ObjectConstructor<T>
get(TypeToken<T> typeToken)

Calls get(TypeToken, boolean), and allows usage of JDK Unsafe.

public <T> ObjectConstructor<T>
get(TypeToken<T>
type for which a constructor should be retrieved
typeToken
,
boolean
whether to allow usage of JDK Unsafe; has no effect if useJdkUnsafe is false
allowUnsafe
)

Retrieves an object constructor for the given type.

private static boolean
private static ObjectConstructor<? extends Collection<?>>
private static <T> ObjectConstructor<T>
private static <T> ObjectConstructor<T>
newDefaultImplementationConstructor(Type type, Class<? super T> rawType)

Constructors for common interface types like Map and List and their subtypes.

private static ObjectConstructor<? extends Map<?, Object>>
newMapConstructor(Type type, Class<?> rawType)

private static <T> ObjectConstructor<T>
newSpecialCollectionConstructor(Type type, Class<? super T> rawType)

Creates constructors for special JDK collection types which do not have a public no-args constructor.

private <T> ObjectConstructor<T>
newUnsafeAllocator(Class<? super T> rawType)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

instanceCreatorsback to summary
private final Map<Type, InstanceCreator<?>> instanceCreators
reflectionFiltersback to summary
private final List<ReflectionAccessFilter> reflectionFilters
useJdkUnsafeback to summary
private final boolean useJdkUnsafe

Constructor Detail

ConstructorConstructorback to summary
public ConstructorConstructor(Map<Type, InstanceCreator<?>> instanceCreators, boolean useJdkUnsafe, List<ReflectionAccessFilter> reflectionFilters)

Method Detail

checkInstantiableback to summary
pack-priv static String checkInstantiable(Class<?> c)

Check if the class can be instantiated by Unsafe allocator. If the instance has interface or abstract modifiers return an exception message.

Parameters
c:Class<?>

instance of the class to be checked

Returns:String

if instantiable null, else a non-null exception message

getback to summary
public <T> ObjectConstructor<T> get(TypeToken<T> typeToken)

Calls get(TypeToken, boolean), and allows usage of JDK Unsafe.

getback to summary
public <T> ObjectConstructor<T> get(TypeToken<T> typeToken, boolean allowUnsafe)

Retrieves an object constructor for the given type.

Parameters
typeToken:TypeToken<T>

type for which a constructor should be retrieved

allowUnsafe:boolean

whether to allow usage of JDK Unsafe; has no effect if useJdkUnsafe is false

hasStringKeyTypeback to summary
private static boolean hasStringKeyType(Type mapType)
newCollectionConstructorback to summary
private static ObjectConstructor<? extends Collection<?>> newCollectionConstructor(Class<?> rawType)
newDefaultConstructorback to summary
private static <T> ObjectConstructor<T> newDefaultConstructor(Class<? super T> rawType, ReflectionAccessFilter.FilterResult filterResult)
newDefaultImplementationConstructorback to summary
private static <T> ObjectConstructor<T> newDefaultImplementationConstructor(Type type, Class<? super T> rawType)

Constructors for common interface types like Map and List and their subtypes.

newMapConstructorback to summary
private static ObjectConstructor<? extends Map<?, Object>> newMapConstructor(Type type, Class<?> rawType)
newSpecialCollectionConstructorback to summary
private static <T> ObjectConstructor<T> newSpecialCollectionConstructor(Type type, Class<? super T> rawType)

Creates constructors for special JDK collection types which do not have a public no-args constructor.

newUnsafeAllocatorback to summary
private <T> ObjectConstructor<T> newUnsafeAllocator(Class<? super T> rawType)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
com.google.gson.internal back to summary

private final Class ConstructorConstructor.InstanceCreatorConstructor<T>

extends Object
implements ObjectConstructor<T>
Class Inheritance
  • java.lang.Object
  • com.google.gson.internal.ConstructorConstructor.InstanceCreatorConstructor
All Implemented Interfaces
com.google.gson.internal.ObjectConstructor

Field Summary

Modifier and TypeField and Description
private final InstanceCreator<T>
private final Type

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public T
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

instanceCreatorback to summary
private final InstanceCreator<T> instanceCreator
typeback to summary
private final Type type

Constructor Detail

InstanceCreatorConstructorback to summary
pack-priv InstanceCreatorConstructor(InstanceCreator<T> instanceCreator, Type type)

Method Detail

constructback to summary
public T construct()

Implements com.google.gson.internal.ObjectConstructor.construct.

Doc from com.google.gson.internal.ObjectConstructor.construct.

Returns a new instance.

Annotations
@Override
com.google.gson.internal back to summary

private final Class ConstructorConstructor.ThrowingObjectConstructor<T>

extends Object
implements ObjectConstructor<T>
Class Inheritance
  • java.lang.Object
  • com.google.gson.internal.ConstructorConstructor.ThrowingObjectConstructor
All Implemented Interfaces
com.google.gson.internal.ObjectConstructor

ObjectConstructor which always throws an exception.

This keeps backward compatibility, compared to using a null ObjectConstructor, which would then choose another way of creating the object. And it supports types which are only serialized but not deserialized (compared to directly throwing an exception when the ObjectConstructor is requested), e.g. when the runtime type of an object is inaccessible, but the compile-time type is accessible.

Field Summary

Modifier and TypeField and Description
private final String

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public T
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

exceptionMessageback to summary
private final String exceptionMessage

Constructor Detail

ThrowingObjectConstructorback to summary
pack-priv ThrowingObjectConstructor(String exceptionMessage)

Method Detail

constructback to summary
public T construct()

Implements com.google.gson.internal.ObjectConstructor.construct.

Doc from com.google.gson.internal.ObjectConstructor.construct.

Returns a new instance.

Annotations
@Override