Class SerializationHelper

java.lang.Object
com.helger.base.serialize.SerializationHelper

@Immutable public final class SerializationHelper extends Object
Global serialization helper method.
Since:
8.5.5
Author:
Philip Helger
  • Method Details

    • getSerializedByteArray

      public static byte @NonNull [] getSerializedByteArray(@NonNull Serializable aData)
      Convert the passed Serializable object to a serialized byte array.
      Parameters:
      aData - Source object. May not be null.
      Returns:
      A non-null byte array.
      Throws:
      IllegalStateException - If serialization failed
    • getDeserializedObject

      public static <T> @NonNull T getDeserializedObject(byte @NonNull [] aData, @Nullable ObjectInputFilter aFilter)
      Convert the passed byte array to an object using deserialization.
      Type Parameters:
      T - The type of the deserialized object
      Parameters:
      aData - The source serialized byte array. Must contain a single object only. May not be null.
      aFilter - An optional ObjectInputFilter to restrict deserialization. May be null.
      Returns:
      The deserialized object. Never null.
      Throws:
      IllegalStateException - If deserialization failed
      Since:
      12.2.1
    • getDeserializedObject

      @Deprecated(since="12.2.1", forRemoval=false) public static <T> @NonNull T getDeserializedObject(byte @NonNull [] aData)
      Deprecated.
      Use getDeserializedObject(byte[], ObjectInputFilter) with an appropriate filter instead.
      Convert the passed byte array to an object using deserialization. This method does not apply any ObjectInputFilter and should only be used with trusted data.
      Type Parameters:
      T - The type of the deserialized object
      Parameters:
      aData - The source serialized byte array. Must contain a single object only. May not be null.
      Returns:
      The deserialized object. Never null.
      Throws:
      IllegalStateException - If deserialization failed