Class SerializableUtils


  • public class SerializableUtils
    extends java.lang.Object
    Utilities for working with Serializables.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T extends java.io.Serializable>
      T
      clone​(T value)  
      static java.lang.Object deserializeFromByteArray​(byte[] encodedValue, java.lang.String description)
      Deserializes an object from the given array of bytes, e.g., as serialized using serializeToByteArray(java.io.Serializable), and returns it.
      static Coder<?> ensureSerializable​(Coder<?> coder)
      Serializes a Coder and verifies that it can be correctly deserialized.
      static <T extends java.io.Serializable>
      T
      ensureSerializable​(T value)  
      static <T> T ensureSerializableByCoder​(Coder<T> coder, T value, java.lang.String errorContext)
      Serializes an arbitrary T with the given Coder<T> and verifies that it can be correctly deserialized.
      static <T extends java.io.Serializable>
      T
      ensureSerializableRoundTrip​(T value)  
      static byte[] serializeToByteArray​(java.io.Serializable value)
      Serializes the argument into an array of bytes, and returns it.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SerializableUtils

        public SerializableUtils()
    • Method Detail

      • serializeToByteArray

        public static byte[] serializeToByteArray​(java.io.Serializable value)
        Serializes the argument into an array of bytes, and returns it.
        Throws:
        java.lang.IllegalArgumentException - if there are errors when serializing
      • deserializeFromByteArray

        public static java.lang.Object deserializeFromByteArray​(byte[] encodedValue,
                                                                java.lang.String description)
        Deserializes an object from the given array of bytes, e.g., as serialized using serializeToByteArray(java.io.Serializable), and returns it.
        Throws:
        java.lang.IllegalArgumentException - if there are errors when deserializing, using the provided description to identify what was being deserialized
      • ensureSerializableRoundTrip

        public static <T extends java.io.Serializable> T ensureSerializableRoundTrip​(T value)
      • ensureSerializable

        public static <T extends java.io.Serializable> T ensureSerializable​(T value)
      • clone

        public static <T extends java.io.Serializable> T clone​(T value)
      • ensureSerializable

        public static Coder<?> ensureSerializable​(Coder<?> coder)
        Serializes a Coder and verifies that it can be correctly deserialized.

        Throws a RuntimeException if serialized Coder cannot be deserialized, or if the deserialized instance is not equal to the original.

        Returns:
        the deserialized Coder
      • ensureSerializableByCoder

        public static <T> T ensureSerializableByCoder​(Coder<T> coder,
                                                      T value,
                                                      java.lang.String errorContext)
        Serializes an arbitrary T with the given Coder<T> and verifies that it can be correctly deserialized.