Class ReflectiveTypeAdapterFactory.Adapter<T,​A>

  • Type Parameters:
    T - type of objects that this Adapter creates.
    A - type of accumulator used to build the deserialization result.
    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 the ReflectiveTypeAdapterFactory.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.

    • 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) for value.
        Specified by:
        write in class TypeAdapter<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 class TypeAdapter<T>
        Returns:
        the converted Java object. May be null.
        Throws:
        java.io.IOException