Interface ObjectSerializer

All Known Implementing Classes:
JacksonObjectSerializer, JdkSerializer, JsonObjectSerializer

public interface ObjectSerializer
Interface for implementations capable of serializing objects.
Since:
1.0
Author:
Graeme Rocher
  • Field Details

  • Method Details

    • serialize

      void serialize(@Nullable Object object, OutputStream outputStream) throws SerializationException
      Serialize the given object to a byte[].
      Parameters:
      object - The object to serialize
      outputStream - The output stream
      Throws:
      SerializationException - if there is a serialization problem
    • deserialize

      <T> Optional<T> deserialize(@Nullable InputStream inputStream, Class<T> requiredType) throws SerializationException
      Deserialize the given object to bytes.
      Type Parameters:
      T - The required generic type
      Parameters:
      inputStream - The input stream
      requiredType - The required type
      Returns:
      An Optional of the object
      Throws:
      SerializationException - if there is a serialization problem
    • deserialize

      default <T> Optional<T> deserialize(@Nullable InputStream inputStream, Argument<T> requiredType) throws SerializationException
      Deserialize the given object to bytes.
      Type Parameters:
      T - The required generic type
      Parameters:
      inputStream - The input stream
      requiredType - The required type
      Returns:
      An Optional of the object
      Throws:
      SerializationException - if there is a serialization problem
      Since:
      2.0
    • serialize

      default Optional<byte[]> serialize(@Nullable Object object) throws SerializationException
      Serialize the given object to a byte[].
      Parameters:
      object - The object to serialize
      Returns:
      An optional of the bytes of the object
      Throws:
      SerializationException - if there is a serialization problem
    • deserialize

      default <T> Optional<T> deserialize(byte @Nullable [] bytes, Class<T> requiredType) throws SerializationException
      Deserialize the given object to bytes.
      Type Parameters:
      T - The required generic type
      Parameters:
      bytes - The byte array
      requiredType - The required type
      Returns:
      An Optional of the object
      Throws:
      SerializationException - if there is a serialization problem
    • deserialize

      default <T> Optional<T> deserialize(byte @Nullable [] bytes, Argument<T> requiredType) throws SerializationException
      Deserialize the given object to bytes.
      Type Parameters:
      T - The required generic type
      Parameters:
      bytes - The byte array
      requiredType - The required type
      Returns:
      An Optional of the object
      Throws:
      SerializationException - if there is a serialization problem
      Since:
      2.0
    • deserialize

      default Optional<Object> deserialize(byte @Nullable [] bytes) throws SerializationException
      Deserialize the given object to bytes.
      Parameters:
      bytes - The byte array
      Returns:
      An Optional of the object
      Throws:
      SerializationException - if there is a serialization problem