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 Summary

    Fields
    Modifier and Type
    Field
    Description
    static final ObjectSerializer
    The default JDK serializer.
  • Method Summary

    Modifier and Type
    Method
    Description
    default Optional<Object>
    deserialize(@org.jspecify.annotations.Nullable byte[] bytes)
    Deserialize the given object to bytes.
    default <T> Optional<T>
    deserialize(@org.jspecify.annotations.Nullable byte[] bytes, Argument<T> requiredType)
    Deserialize the given object to bytes.
    default <T> Optional<T>
    deserialize(@org.jspecify.annotations.Nullable byte[] bytes, Class<T> requiredType)
    Deserialize the given object to bytes.
    default <T> Optional<T>
    deserialize(@Nullable InputStream inputStream, Argument<T> requiredType)
    Deserialize the given object to bytes.
    <T> Optional<T>
    deserialize(@Nullable InputStream inputStream, Class<T> requiredType)
    Deserialize the given object to bytes.
    default Optional<byte[]>
    serialize(@Nullable Object object)
    Serialize the given object to a byte[].
    void
    serialize(@Nullable Object object, OutputStream outputStream)
    Serialize the given object to a byte[].
  • 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(@org.jspecify.annotations.Nullable byte[] 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(@org.jspecify.annotations.Nullable byte[] 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(@org.jspecify.annotations.Nullable byte[] 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