Package org.apache.beam.sdk.util
Class SerializableUtils
- java.lang.Object
-
- org.apache.beam.sdk.util.SerializableUtils
-
public class SerializableUtils extends java.lang.Object
Utilities for working with Serializables.
-
-
Constructor Summary
Constructors Constructor Description SerializableUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends java.io.Serializable>
Tclone(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 usingserializeToByteArray(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>
TensureSerializable(T value)
static <T> T
ensureSerializableByCoder(Coder<T> coder, T value, java.lang.String errorContext)
Serializes an arbitrary T with the givenCoder<T>
and verifies that it can be correctly deserialized.static <T extends java.io.Serializable>
TensureSerializableRoundTrip(T value)
static byte[]
serializeToByteArray(java.io.Serializable value)
Serializes the argument into an array of bytes, and returns it.
-
-
-
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 usingserializeToByteArray(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 givenCoder<T>
and verifies that it can be correctly deserialized.
-
-