Interface Serializer


public interface Serializer
Supports writing and reading of object instances to/from a pipe.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default Serializer
    adapt(Object descriptor)
    Adapts this serializer to conform to the given descriptor or else returns this instance if no adaptation is required.
    default Object
    Returns an opaque serializable object describing the encoding format.
    read(Pipe pipe)
    Reads an object from the pipe.
    static Serializer
    simple(Class<?> type)
    Generates and returns a serializer for a record type, an enum type, or a simple class.
    default void
    skip(Pipe pipe, Consumer<Object> remoteConsumer)
    Skip an object instead of reading it.
    Returns a non-null set of classes.
    void
    write(Pipe pipe, Object obj)
    Writes a non-null object to the pipe.
  • Method Details

    • simple

      static Serializer simple(Class<?> type)
      Generates and returns a serializer for a record type, an enum type, or a simple class. A simple class must have a public no-arg constructor, and only public fields are serialized. Static and transient fields aren't serialized either.
      Throws:
      IllegalArgumentException - if the given type isn't supported
    • supportedTypes

      Set<Class<?>> supportedTypes()
      Returns a non-null set of classes.
    • write

      void write(Pipe pipe, Object obj) throws IOException
      Writes a non-null object to the pipe.
      Throws:
      IOException
    • read

      Object read(Pipe pipe) throws IOException
      Reads an object from the pipe. The returned object can be null.
      Throws:
      IOException
    • skip

      default void skip(Pipe pipe, Consumer<Object> remoteConsumer) throws IOException
      Skip an object instead of reading it. By default, the read method is called.
      Parameters:
      remoteConsumer - receives all client-side remote objects, which aren't truly skipped; can pass null to do nothing with them
      Throws:
      IOException
    • descriptor

      default Object descriptor()
      Returns an opaque serializable object describing the encoding format. The descriptor type itself can only depend on built-in serializers and is typically a string.
    • adapt

      default Serializer adapt(Object descriptor)
      Adapts this serializer to conform to the given descriptor or else returns this instance if no adaptation is required. If adaptation isn't possible, can return null to specify a serializer which always reads and writes null, thus discarding the object entirely.
      Parameters:
      descriptor - an object which was provided by the descriptor() method