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
    Deprecated, for removal: This API element is subject to removal in a future version.
    JDK serialization is insecure when deserializing data that can be influenced by an attacker.
  • Method Summary

    Modifier and Type
    Method
    Description
    default Optional<Object>
    deserialize(byte @Nullable [] bytes)
    Deserialize the given object to bytes.
    default <T> Optional<T>
    deserialize(byte @Nullable [] bytes, Argument<T> requiredType)
    Deserialize the given object to bytes.
    default <T> Optional<T>
    deserialize(byte @Nullable [] 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

    • JDK

      @Deprecated(since="5.2", forRemoval=true) static final ObjectSerializer JDK
      Deprecated, for removal: This API element is subject to removal in a future version.
      JDK serialization is insecure when deserializing data that can be influenced by an attacker. Use a safer serialization format instead.
      The default JDK serializer.
  • 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