com.google.cloud.dataflow.sdk.coders

## Class SerializableCoder<T extends Serializable>

- java.lang.Object
- - com.google.cloud.dataflow.sdk.coders.StandardCoder<T>
  - - com.google.cloud.dataflow.sdk.coders.DeterministicStandardCoder<T>
    - - com.google.cloud.dataflow.sdk.coders.AtomicCoder<T>
      - - com.google.cloud.dataflow.sdk.coders.SerializableCoder<T>

Type Parameters:
  `T` - the type of elements handled by this coder

All Implemented Interfaces:
  Coder<T>, Serializable

    public class SerializableCoder<T extends Serializable>
    extends AtomicCoder<T>

A `Coder` for Java classes that implement `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.

See Also:
  Serialized Form

### Nested Class Summary

### Nested classes/interfaces inherited from interface com.google.cloud.dataflow.sdk.coders.Coder

`Coder.Context, Coder.NonDeterministicException`

### Field Summary

Fields
`static CoderProvider` `PROVIDER` A `CoderProvider` that constructs a `SerializableCoder` for any class that implements serializable.

### Constructor Summary

Constructors
`protected` `SerializableCoder(Class<T> type)`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`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)`
`String` `getEncodingId()` An identifier for the binary format written by `Coder.encode(T, java.io.OutputStream, com.google.cloud.dataflow.sdk.coders.Coder.Context)`.
`Class<T>` `getRecordType()`
`int` `hashCode()`
`static <T extends Serializable> SerializableCoder<T>` `of(Class<T> clazz)` Returns a `SerializableCoder` instance for the provided element class.
`static SerializableCoder<?>` `of(String classType)`
`static <T extends Serializable> SerializableCoder<T>` `of(TypeDescriptor<T> type)` Returns a `SerializableCoder` instance for the provided element type.
`void` `verifyDeterministic()` Throw `Coder.NonDeterministicException` if the coding is not deterministic.

### Methods inherited from class com.google.cloud.dataflow.sdk.coders.AtomicCoder

`getCoderArguments, getInstanceComponents`

### Methods inherited from class com.google.cloud.dataflow.sdk.coders.StandardCoder

`consistentWithEquals, getAllowedEncodings, getComponents, getEncodedElementByteSize, isRegisterByteSizeObserverCheap, registerByteSizeObserver, structuralValue, toString, verifyDeterministic, verifyDeterministic`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Field Detail

#### PROVIDER

    public static final CoderProvider PROVIDER

A `CoderProvider` that constructs a `SerializableCoder` for any class that implements serializable.

### Constructor Detail

#### SerializableCoder

    protected SerializableCoder(Class<T> type)

### Method Detail

#### of

    public static <T extends Serializable> SerializableCoder<T> of(TypeDescriptor<T> type)

Returns a `SerializableCoder` instance for the provided element type.

Type Parameters:
  `T` - the element type

#### of

    public static <T extends Serializable> SerializableCoder<T> of(Class<T> clazz)

Returns a `SerializableCoder` instance for the provided element class.

Type Parameters:
  `T` - the element type

#### of

    public static SerializableCoder<?> of(String classType)
                                   throws ClassNotFoundException

Throws:
  `ClassNotFoundException`

#### getRecordType

    public Class<T> getRecordType()

#### encode

    public void encode(T value,
                       OutputStream outStream,
                       Coder.Context context)
                throws IOException,
                       CoderException

Description copied from interface: `Coder`
Encodes the given value of type `T` onto the given output stream in the given context.

Throws:
  `IOException` - if writing to the `OutputStream` fails for some reason
  `CoderException` - if the value could not be encoded for some reason

#### decode

    public T decode(InputStream inStream,
                    Coder.Context context)
             throws IOException,
                    CoderException

Description copied from interface: `Coder`
Decodes a value of type `T` from the given input stream in the given context. Returns the decoded value.

Throws:
  `IOException` - if reading from the `InputStream` fails for some reason
  `CoderException` - if the value could not be decoded for some reason

#### getEncodingId

    public String getEncodingId()

Description copied from interface: `Coder`
An identifier for the binary format written by `Coder.encode(T, java.io.OutputStream, com.google.cloud.dataflow.sdk.coders.Coder.Context)`.

This value, along with the fully qualified class name, forms an identifier for the binary format of this coder. Whenever this value changes, the new encoding is considered incompatible with the prior format: It is presumed that the prior version of the coder will be unable to correctly read the new format and the new version of the coder will be unable to correctly read the old format.

If the format is changed in a backwards-compatible way (the Coder can still accept data from the prior format), such as by adding optional fields to a Protocol Buffer or Avro definition, and you want Dataflow to understand that the new coder is compatible with the prior coder, this value must remain unchanged. It is then the responsibility of `Coder.decode(java.io.InputStream, com.google.cloud.dataflow.sdk.coders.Coder.Context)` to correctly read data from the prior format.

Specified by:
  `getEncodingId` in interface `Coder<T extends Serializable>`
Overrides:
  `getEncodingId` in class `StandardCoder<T extends Serializable>`

#### asCloudObject

    public com.google.cloud.dataflow.sdk.util.CloudObject asCloudObject()

Description copied from interface: `Coder`
Returns the `CloudObject` that represents this `Coder`.

Specified by:
  `asCloudObject` in interface `Coder<T extends Serializable>`
Overrides:
  `asCloudObject` in class `StandardCoder<T extends Serializable>`

#### verifyDeterministic

    public void verifyDeterministic()
                             throws Coder.NonDeterministicException

Throw `Coder.NonDeterministicException` if the coding is not deterministic.

In order for a `Coder` to be considered deterministic, the following must be true:

- two values that compare as equal (via `Object.equals()` or `Comparable.compareTo()`, if supported) have the same encoding.
- the `Coder` always produces a canonical encoding, which is the same for an instance of an object even if produced on different computers at different times.

Specified by:
  `verifyDeterministic` in interface `Coder<T extends Serializable>`
Overrides:
  `verifyDeterministic` in class `DeterministicStandardCoder<T extends Serializable>`
Throws:
  `NonDeterministicException` - always. Java serialization is not deterministic with respect to `Object.equals(java.lang.Object)` for all types.
  `Coder.NonDeterministicException` - if this coder is not deterministic.

#### equals

    public boolean equals(Object other)

Description copied from class: `StandardCoder`

Overrides:
  `equals` in class `StandardCoder<T extends Serializable>`
Returns:
  `true` if the two `StandardCoder` instances have the same class and equal components.

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `StandardCoder<T extends Serializable>`