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

public final Class ReflectiveTypeAdapterFactory

extends Object
implements TypeAdapterFactory
Class Inheritance
All Implemented Interfaces
com.google.gson.TypeAdapterFactory
Imports
com.google.gson.FieldNamingStrategy, .Gson, .JsonIOException, .JsonParseException, .JsonSyntaxException, .ReflectionAccessFilter, .ReflectionAccessFilter.FilterResult, .TypeAdapter, .TypeAdapterFactory, com.google.gson.annotations.JsonAdapter, .SerializedName, com.google.gson.internal.ConstructorConstructor, .Excluder, .GsonTypes, .ObjectConstructor, .Primitives, .ReflectionAccessFilterHelper, .TroubleshootingGuide, com.google.gson.internal.reflect.ReflectionHelper, com.google.gson.reflect.TypeToken, com.google.gson.stream.JsonReader, .JsonToken, .JsonWriter, java.io.IOException, java.lang.reflect.AccessibleObject, .Constructor, .Field, .InvocationTargetException, .Member, .Method, .Modifier, .Type, java.util.ArrayList, .Arrays, .Collections, .HashMap, .LinkedHashMap, .List, .Map

Type adapter that reflects over the fields and methods of a class.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
ReflectiveTypeAdapterFactory.Adapter<
type of objects that this Adapter creates.
T
,
type of accumulator used to build the deserialization result.
A
>

Base class for Adapters produced by this factory.

pack-priv abstract static class
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private final ConstructorConstructor
private final Excluder
private final FieldNamingStrategy
private final JsonAdapterAnnotationTypeAdapterFactory
private final List<ReflectionAccessFilter>

Constructor Summary

AccessConstructor and Description
public
ReflectiveTypeAdapterFactory(ConstructorConstructor constructorConstructor, FieldNamingStrategy fieldNamingPolicy, Excluder excluder, JsonAdapterAnnotationTypeAdapterFactory jsonAdapterFactory, List<ReflectionAccessFilter> reflectionFilters)

Method Summary

Modifier and TypeMethod and Description
private static <M extends AccessibleObject & Member> void
checkAccessible(Object object, M member)

public <T> TypeAdapter<T>
create(Gson gson, TypeToken<T> type)

Implements com.google.gson.TypeAdapterFactory.create.

Returns a type adapter for type, or null if this factory doesn't support type.

private ReflectiveTypeAdapterFactory.BoundField
createBoundField(Gson context, Field field, Method accessor, String serializedName, TypeToken<?> fieldType, boolean serialize, boolean blockInaccessible)

private static IllegalArgumentException
createDuplicateFieldException(Class<?> declaringType, String duplicateName, Field field1, Field field2)

private ReflectiveTypeAdapterFactory.FieldsData
getBoundFields(Gson context, TypeToken<?> type, Class<?> raw, boolean blockInaccessible, boolean isRecord)

private List<String>
getFieldNames(Field f)

first element holds the default name

private boolean
includeField(Field f, boolean serialize)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

constructorConstructorback to summary
private final ConstructorConstructor constructorConstructor
excluderback to summary
private final Excluder excluder
fieldNamingPolicyback to summary
private final FieldNamingStrategy fieldNamingPolicy
jsonAdapterFactoryback to summary
private final JsonAdapterAnnotationTypeAdapterFactory jsonAdapterFactory
reflectionFiltersback to summary
private final List<ReflectionAccessFilter> reflectionFilters

Constructor Detail

ReflectiveTypeAdapterFactoryback to summary
public ReflectiveTypeAdapterFactory(ConstructorConstructor constructorConstructor, FieldNamingStrategy fieldNamingPolicy, Excluder excluder, JsonAdapterAnnotationTypeAdapterFactory jsonAdapterFactory, List<ReflectionAccessFilter> reflectionFilters)

Method Detail

checkAccessibleback to summary
private static <M extends AccessibleObject & Member> void checkAccessible(Object object, M member)
createback to summary
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type)

Implements com.google.gson.TypeAdapterFactory.create.

Doc from com.google.gson.TypeAdapterFactory.create.

Returns a type adapter for type, or null if this factory doesn't support type.

Annotations
@Override
createBoundFieldback to summary
private ReflectiveTypeAdapterFactory.BoundField createBoundField(Gson context, Field field, Method accessor, String serializedName, TypeToken<?> fieldType, boolean serialize, boolean blockInaccessible)
createDuplicateFieldExceptionback to summary
private static IllegalArgumentException createDuplicateFieldException(Class<?> declaringType, String duplicateName, Field field1, Field field2)
getBoundFieldsback to summary
private ReflectiveTypeAdapterFactory.FieldsData getBoundFields(Gson context, TypeToken<?> type, Class<?> raw, boolean blockInaccessible, boolean isRecord)
getFieldNamesback to summary
private List<String> getFieldNames(Field f)

first element holds the default name

Annotations
@SuppressWarnings:MixedMutabilityReturnType
includeFieldback to summary
private boolean includeField(Field f, boolean serialize)
com.google.gson.internal.bind back to summary

public abstract Class ReflectiveTypeAdapterFactory.Adapter<T, A>

extends TypeAdapter<T>
Class Inheritance
Known Direct Subclasses
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.FieldReflectionAdapter, com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.RecordAdapter
Type Parameters
<T>
type of objects that this Adapter creates.
<A>
type of accumulator used to build the deserialization result.

Base class for Adapters produced by this factory.

The RecordAdapter is a special case to handle records for JVMs that support it, for all other types we use the FieldReflectionAdapter. This class encapsulates the common logic for serialization and deserialization. During deserialization, we construct an accumulator A, which we use to accumulate values from the source JSON. After the object has been read in full, the finalize(Object) method is used to convert the accumulator to an instance of T.

Field Summary

Modifier and TypeField and Description
private final ReflectiveTypeAdapterFactory.FieldsData

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract A
createAccumulator()

Create the Object that will be used to collect each field value

pack-priv abstract T
finalize(A accumulator)

Convert the accumulator to a final instance of T.

public T
read(JsonReader in)

Implements abstract com.google.gson.TypeAdapter.read.

Reads one JSON value (an array, object, string, number, boolean or null) and converts it to a Java object.

pack-priv abstract void
readField(A accumulator, JsonReader in, ReflectiveTypeAdapterFactory.BoundField field)

Read a single BoundField into the accumulator.

public void
write(JsonWriter out, T value)

Implements abstract com.google.gson.TypeAdapter.write.

Writes one JSON value (an array, object, string, number, boolean or null) for value.

Inherited from com.google.gson.TypeAdapter:
fromJsonfromJsonfromJsonTreenullSafetoJsontoJsontoJsonTree

Field Detail

fieldsDataback to summary
private final ReflectiveTypeAdapterFactory.FieldsData fieldsData

Constructor Detail

Adapterback to summary
pack-priv Adapter(ReflectiveTypeAdapterFactory.FieldsData fieldsData)

Method Detail

createAccumulatorback to summary
pack-priv abstract A createAccumulator()

Create the Object that will be used to collect each field value

finalizeback to summary
pack-priv abstract T finalize(A accumulator)

Convert the accumulator to a final instance of T.

readback to summary
public T read(JsonReader in) throws IOException

Implements abstract com.google.gson.TypeAdapter.read.

Doc from com.google.gson.TypeAdapter.read.

Reads one JSON value (an array, object, string, number, boolean or null) and converts it to a Java object. Returns the converted object.

Annotations
@Override
readFieldback to summary
pack-priv abstract void readField(A accumulator, JsonReader in, ReflectiveTypeAdapterFactory.BoundField field) throws IllegalAccessException, IOException

Read a single BoundField into the accumulator. The JsonReader will be pointed at the start of the value for the BoundField to read from.

writeback to summary
public void write(JsonWriter out, T value) throws IOException

Implements abstract com.google.gson.TypeAdapter.write.

Doc from com.google.gson.TypeAdapter.write.

Writes one JSON value (an array, object, string, number, boolean or null) for value.

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

pack-priv abstract Class ReflectiveTypeAdapterFactory.BoundField

extends Object
Class Inheritance
  • java.lang.Object
  • com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.BoundField

Field Summary

Modifier and TypeField and Description
pack-priv final Field
pack-priv final String
fieldName

Name of the underlying field

pack-priv final String
serializedName

Name used for serialization (but not for deserialization)

Constructor Summary

AccessConstructor and Description
protected
BoundField(String serializedName, Field field)

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract void
readIntoArray(JsonReader reader, int index, Object[] target)

Read the value into the target array, used to provide constructor arguments for records

pack-priv abstract void
readIntoField(JsonReader reader, Object target)

Read the value from the reader, and set it on the corresponding field on target via reflection

pack-priv abstract void
write(JsonWriter writer, Object source)

Read this field value from the source, and append its JSON value to the writer

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fieldback to summary
pack-priv final Field field
fieldNameback to summary
pack-priv final String fieldName

Name of the underlying field

serializedNameback to summary
pack-priv final String serializedName

Name used for serialization (but not for deserialization)

Constructor Detail

BoundFieldback to summary
protected BoundField(String serializedName, Field field)

Method Detail

readIntoArrayback to summary
pack-priv abstract void readIntoArray(JsonReader reader, int index, Object[] target) throws IOException, JsonParseException

Read the value into the target array, used to provide constructor arguments for records

readIntoFieldback to summary
pack-priv abstract void readIntoField(JsonReader reader, Object target) throws IOException, IllegalAccessException

Read the value from the reader, and set it on the corresponding field on target via reflection

writeback to summary
pack-priv abstract void write(JsonWriter writer, Object source) throws IOException, IllegalAccessException

Read this field value from the source, and append its JSON value to the writer

com.google.gson.internal.bind back to summary

private final Class ReflectiveTypeAdapterFactory.FieldReflectionAdapter<T>

extends ReflectiveTypeAdapterFactory.Adapter<T, T>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final ObjectConstructor<T>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv T
createAccumulator()

Implements abstract com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter.createAccumulator.

Create the Object that will be used to collect each field value

pack-priv T
finalize(T accumulator)

Implements abstract com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter.finalize.

Convert the accumulator to a final instance of T.

pack-priv void
readField(T accumulator, JsonReader in, ReflectiveTypeAdapterFactory.BoundField field)

Implements abstract com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter.readField.

Read a single BoundField into the accumulator.

Inherited from com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter:
readwrite

Field Detail

constructorback to summary
private final ObjectConstructor<T> constructor

Constructor Detail

FieldReflectionAdapterback to summary
pack-priv FieldReflectionAdapter(ObjectConstructor<T> constructor, ReflectiveTypeAdapterFactory.FieldsData fieldsData)

Method Detail

createAccumulatorback to summary
pack-priv T createAccumulator()

Implements abstract com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter.createAccumulator.

Doc from com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter.createAccumulator.

Create the Object that will be used to collect each field value

Annotations
@Override
finalizeback to summary
pack-priv T finalize(T accumulator)

Implements abstract com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter.finalize.

Doc from com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter.finalize.

Convert the accumulator to a final instance of T.

Annotations
@Override
readFieldback to summary
pack-priv void readField(T accumulator, JsonReader in, ReflectiveTypeAdapterFactory.BoundField field) throws IllegalAccessException, IOException

Implements abstract com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter.readField.

Doc from com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter.readField.

Read a single BoundField into the accumulator. The JsonReader will be pointed at the start of the value for the BoundField to read from.

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

private Class ReflectiveTypeAdapterFactory.FieldsData

extends Object
Class Inheritance
  • java.lang.Object
  • com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.FieldsData

Field Summary

Modifier and TypeField and Description
pack-priv final Map<String, ReflectiveTypeAdapterFactory.BoundField>
deserializedFields

Maps from JSON member name to field

pack-priv static final ReflectiveTypeAdapterFactory.FieldsData
pack-priv final List<ReflectiveTypeAdapterFactory.BoundField>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

deserializedFieldsback to summary
pack-priv final Map<String, ReflectiveTypeAdapterFactory.BoundField> deserializedFields

Maps from JSON member name to field

EMPTYback to summary
pack-priv static final ReflectiveTypeAdapterFactory.FieldsData EMPTY
serializedFieldsback to summary
pack-priv final List<ReflectiveTypeAdapterFactory.BoundField> serializedFields

Constructor Detail

FieldsDataback to summary
pack-priv FieldsData(Map<String, ReflectiveTypeAdapterFactory.BoundField> deserializedFields, List<ReflectiveTypeAdapterFactory.BoundField> serializedFields)
com.google.gson.internal.bind back to summary

private final Class ReflectiveTypeAdapterFactory.RecordAdapter<T>

extends ReflectiveTypeAdapterFactory.Adapter<T, Object[]>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Map<String, Integer>
private final Constructor<T>
private final Object[]
pack-priv static final Map<Class<?>, Object>

Constructor Summary

AccessConstructor and Description
pack-priv
RecordAdapter(Class<T> raw, ReflectiveTypeAdapterFactory.FieldsData fieldsData, boolean blockInaccessible)

Method Summary

Modifier and TypeMethod and Description
pack-priv Object[]
createAccumulator()

Implements abstract com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter.createAccumulator.

Create the Object that will be used to collect each field value

pack-priv T
finalize(Object[] accumulator)

Implements abstract com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter.finalize.

Convert the accumulator to a final instance of T.

private static Map<Class<?>, Object>
pack-priv void
readField(Object[] accumulator, JsonReader in, ReflectiveTypeAdapterFactory.BoundField field)

Implements abstract com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter.readField.

Read a single BoundField into the accumulator.

Inherited from com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter:
readwrite

Field Detail

componentIndicesback to summary
private final Map<String, Integer> componentIndices
constructorback to summary
private final Constructor<T> constructor
constructorArgsDefaultsback to summary
private final Object[] constructorArgsDefaults
PRIMITIVE_DEFAULTSback to summary
pack-priv static final Map<Class<?>, Object> PRIMITIVE_DEFAULTS

Constructor Detail

RecordAdapterback to summary
pack-priv RecordAdapter(Class<T> raw, ReflectiveTypeAdapterFactory.FieldsData fieldsData, boolean blockInaccessible)

Method Detail

createAccumulatorback to summary
pack-priv Object[] createAccumulator()

Implements abstract com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter.createAccumulator.

Doc from com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter.createAccumulator.

Create the Object that will be used to collect each field value

Annotations
@Override
finalizeback to summary
pack-priv T finalize(Object[] accumulator)

Implements abstract com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter.finalize.

Doc from com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter.finalize.

Convert the accumulator to a final instance of T.

Annotations
@Override
primitiveDefaultsback to summary
private static Map<Class<?>, Object> primitiveDefaults()
readFieldback to summary
pack-priv void readField(Object[] accumulator, JsonReader in, ReflectiveTypeAdapterFactory.BoundField field) throws IOException

Implements abstract com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter.readField.

Doc from com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter.readField.

Read a single BoundField into the accumulator. The JsonReader will be pointed at the start of the value for the BoundField to read from.

Annotations
@Override