Package com.google.gson.internal.bind
Class ReflectiveTypeAdapterFactory.Adapter<T,A>
- java.lang.Object
-
- com.google.gson.TypeAdapter<T>
-
- com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.Adapter<T,A>
-
- Type Parameters:
T
- type of objects that this Adapter creates.A
- type of accumulator used to build the deserialization result.
- Direct Known Subclasses:
ReflectiveTypeAdapterFactory.FieldReflectionAdapter
,ReflectiveTypeAdapterFactory.RecordAdapter
- Enclosing class:
- ReflectiveTypeAdapterFactory
public abstract static class ReflectiveTypeAdapterFactory.Adapter<T,A> extends TypeAdapter<T>
Base class for Adapters produced by this factory.The
ReflectiveTypeAdapterFactory.RecordAdapter
is a special case to handle records for JVMs that support it, for all other types we use theReflectiveTypeAdapterFactory.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, thefinalize(Object)
method is used to convert the accumulator to an instance of T.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.Map<java.lang.String,ReflectiveTypeAdapterFactory.BoundField>
boundFields
-
Constructor Summary
Constructors Constructor Description Adapter(java.util.Map<java.lang.String,ReflectiveTypeAdapterFactory.BoundField> boundFields)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) abstract A
createAccumulator()
Create the Object that will be used to collect each field value(package private) abstract T
finalize(A accumulator)
Convert the accumulator to a final instance of T.T
read(JsonReader in)
Reads one JSON value (an array, object, string, number, boolean or null) and converts it to a Java object.(package private) abstract void
readField(A accumulator, JsonReader in, ReflectiveTypeAdapterFactory.BoundField field)
Read a single BoundField into the accumulator.void
write(JsonWriter out, T value)
Writes one JSON value (an array, object, string, number, boolean or null) forvalue
.-
Methods inherited from class com.google.gson.TypeAdapter
fromJson, fromJson, fromJsonTree, nullSafe, toJson, toJson, toJsonTree
-
-
-
-
Field Detail
-
boundFields
final java.util.Map<java.lang.String,ReflectiveTypeAdapterFactory.BoundField> boundFields
-
-
Constructor Detail
-
Adapter
Adapter(java.util.Map<java.lang.String,ReflectiveTypeAdapterFactory.BoundField> boundFields)
-
-
Method Detail
-
write
public void write(JsonWriter out, T value) throws java.io.IOException
Description copied from class:TypeAdapter
Writes one JSON value (an array, object, string, number, boolean or null) forvalue
.- Specified by:
write
in classTypeAdapter<T>
value
- the Java object to write. May be null.- Throws:
java.io.IOException
-
read
public T read(JsonReader in) throws java.io.IOException
Description copied from class:TypeAdapter
Reads one JSON value (an array, object, string, number, boolean or null) and converts it to a Java object. Returns the converted object.- Specified by:
read
in classTypeAdapter<T>
- Returns:
- the converted Java object. May be null.
- Throws:
java.io.IOException
-
createAccumulator
abstract A createAccumulator()
Create the Object that will be used to collect each field value
-
readField
abstract void readField(A accumulator, JsonReader in, ReflectiveTypeAdapterFactory.BoundField field) throws java.lang.IllegalAccessException, java.io.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.- Throws:
java.lang.IllegalAccessException
java.io.IOException
-
-