T - the type of elements handled by this coderpublic class SerializableCoder<T extends Serializable> extends AtomicCoder<T>
SerializableCoder is a Coder for a
Java class that implements Serializable.
To use, specify the coder type on a PCollection:
PCollection<MyRecord> records =
foo.apply(...).setCoder(SerializableCoder.of(MyRecord.class));
SerializableCoder does not guarantee a deterministic encoding, as Java Serialization may produce different binary encodings for two equivalent objects.
Coder.Context, Coder.NonDeterministicException| Modifier and Type | Field and Description |
|---|---|
static CoderProvider |
PROVIDER
A
CoderProvider that constructs a SerializableCoder
for any class that implements serializable. |
| Modifier | Constructor and Description |
|---|---|
protected |
SerializableCoder(Class<T> type) |
| Modifier and Type | Method and Description |
|---|---|
com.google.cloud.dataflow.sdk.util.CloudObject |
asCloudObject()
Returns the
CloudObject that represents this Coder. |
T |
decode(InputStream inStream,
Coder.Context context)
Decodes a value of type
T from the given input stream in
the given context. |
void |
encode(T value,
OutputStream outStream,
Coder.Context context)
Encodes the given value of type
T onto the given output stream
in the given context. |
boolean |
equals(Object other) |
Class<T> |
getRecordType() |
int |
hashCode() |
static <T extends Serializable> |
of(Class<T> clazz)
Returns a
SerializableCoder instance for the provided element class. |
static SerializableCoder<?> |
of(String classType) |
void |
verifyDeterministic()
As a
DeterministicStandardCoder is presumed deterministic, this
method does nothing. |
getCoderArguments, getInstanceComponentsconsistentWithEquals, getComponents, getEncodedElementByteSize, isRegisterByteSizeObserverCheap, registerByteSizeObserver, structuralValue, toString, verifyDeterministic, verifyDeterministicpublic static final CoderProvider PROVIDER
CoderProvider that constructs a SerializableCoder
for any class that implements serializable.public static <T extends Serializable> SerializableCoder<T> of(Class<T> clazz)
SerializableCoder instance for the provided element class.T - the element typepublic static SerializableCoder<?> of(String classType) throws ClassNotFoundException
ClassNotFoundExceptionpublic void encode(T value, OutputStream outStream, Coder.Context context) throws IOException, CoderException
CoderT onto the given output stream
in the given context.IOException - if writing to the OutputStream fails
for some reasonCoderException - if the value could not be encoded for some reasonpublic T decode(InputStream inStream, Coder.Context context) throws IOException, CoderException
CoderT from the given input stream in
the given context. Returns the decoded value.IOException - if reading from the InputStream fails
for some reasonCoderException - if the value could not be decoded for some reasonpublic com.google.cloud.dataflow.sdk.util.CloudObject asCloudObject()
CoderCloudObject that represents this Coder.asCloudObject in interface Coder<T extends Serializable>asCloudObject in class StandardCoder<T extends Serializable>public void verifyDeterministic()
throws Coder.NonDeterministicException
DeterministicStandardCoderDeterministicStandardCoder is presumed deterministic, this
method does nothing.verifyDeterministic in interface Coder<T extends Serializable>verifyDeterministic in class DeterministicStandardCoder<T extends Serializable>Coder.NonDeterministicException - if this coder is not deterministic.public boolean equals(Object other)
equals in class StandardCoder<T extends Serializable>public int hashCode()
hashCode in class StandardCoder<T extends Serializable>