Package com.google.gson.internal
Class ConstructorConstructor
java.lang.Object
com.google.gson.internal.ConstructorConstructor
Returns a function that can construct an instance of a requested type.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classprivate static final classObjectConstructorwhich always throws an exception. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<Type,InstanceCreator<?>> private final List<ReflectionAccessFilter>private final boolean -
Constructor Summary
ConstructorsConstructorDescriptionConstructorConstructor(Map<Type, InstanceCreator<?>> instanceCreators, boolean useJdkUnsafe, List<ReflectionAccessFilter> reflectionFilters) -
Method Summary
Modifier and TypeMethodDescription(package private) static StringcheckInstantiable(Class<?> c) Check if the class can be instantiated by Unsafe allocator.<T> ObjectConstructor<T>Callsget(TypeToken, boolean), and allows usage of JDK Unsafe.<T> ObjectConstructor<T>Retrieves an object constructor for the given type.private static booleanhasStringKeyType(Type mapType) private static ObjectConstructor<? extends Collection<?>>newCollectionConstructor(Class<?> rawType) private static <T> ObjectConstructor<T>newDefaultConstructor(Class<? super T> rawType, ReflectionAccessFilter.FilterResult filterResult) 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) toString()
-
Field Details
-
instanceCreators
-
useJdkUnsafe
private final boolean useJdkUnsafe -
reflectionFilters
-
-
Constructor Details
-
ConstructorConstructor
public ConstructorConstructor(Map<Type, InstanceCreator<?>> instanceCreators, boolean useJdkUnsafe, List<ReflectionAccessFilter> reflectionFilters)
-
-
Method Details
-
checkInstantiable
Check if the class can be instantiated by Unsafe allocator. If the instance has interface or abstract modifiers return an exception message.- Parameters:
c- instance of the class to be checked- Returns:
- if instantiable
null, else a non-nullexception message
-
get
Callsget(TypeToken, boolean), and allows usage of JDK Unsafe. -
get
Retrieves an object constructor for the given type.- Parameters:
typeToken- type for which a constructor should be retrievedallowUnsafe- whether to allow usage of JDK Unsafe; has no effect ifuseJdkUnsafeis false
-
newSpecialCollectionConstructor
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. -
newDefaultConstructor
private static <T> ObjectConstructor<T> newDefaultConstructor(Class<? super T> rawType, ReflectionAccessFilter.FilterResult filterResult) -
newDefaultImplementationConstructor
private static <T> ObjectConstructor<T> newDefaultImplementationConstructor(Type type, Class<? super T> rawType) Constructors for common interface types like Map and List and their subtypes. -
newCollectionConstructor
private static ObjectConstructor<? extends Collection<?>> newCollectionConstructor(Class<?> rawType) -
hasStringKeyType
-
newMapConstructor
private static ObjectConstructor<? extends Map<?,Object>> newMapConstructor(Type type, Class<?> rawType) -
newUnsafeAllocator
-
toString
-