Interface SerialCodec<T>

Type Parameters:
T - the type

public interface SerialCodec<T>
Reads and writes one type in Java's serialization format.

Written by the Gradle plugin for every type annotated SerialType. A hand-written one registered for the same type replaces it, which is the escape hatch for a shape the generator refuses.

Since:
1.0.0
  • Method Details

    • descriptors

      List<SerialDescriptor> descriptors()
      Returns the class hierarchy's descriptors, most derived first.

      The format writes the chain so a reader knows which fields belong to which level. A class whose superclass is not serializable has one entry.

      Returns:
      the class hierarchy's descriptors, most derived first
    • writeData

      void writeData(T value, SerialSink sink)
      Writes every field value.

      Most super class first, and within each class the order of its SerialDescriptor.fields. That is the order the format fixes, so the generator emits the calls and this does not choose.

      Parameters:
      value - the object
      sink - where the values go
    • readData

      T readData(SerialSource source)
      Reads every field value back and builds the object.

      The instance is built from the values rather than allocated and filled, because there is no Unsafe on this platform to allocate one without running a constructor. A record is built through its canonical constructor and anything else through its no-argument constructor.

      Parameters:
      source - where the values come from
      Returns:
      the object