Google Cloud Dataflow SDK for Java, version 1.9.1
Annotation Type DefaultCoder
-
@Documented @Retention(value=RUNTIME) @Target(value=TYPE) public @interface DefaultCoder
TheDefaultCoder
annotation specifies a defaultCoder
class to handle encoding and decoding instances of the annotated class.The specified
Coder
must satisfy the requirements ofCoderProviders.fromStaticMethods(java.lang.Class<T>)
. Two classes provided by the SDK that are intended for use with this annotation includeSerializableCoder
andAvroCoder
.To configure the use of Java serialization as the default for a class, annotate the class to use
SerializableCoder
as follows:@DefaultCoder(SerializableCoder.class) public class MyCustomDataType implements Serializable { // ... }
Similarly, to configure the use of
AvroCoder
as the default:@DefaultCoder(AvroCoder.class) public class MyCustomDataType { public MyCustomDataType() {} // Avro requires an empty constructor. // ... }
Coders specified explicitly via
PCollection.setCoder(com.google.cloud.dataflow.sdk.coders.Coder<T>)
take precedence, followed by Coders registered at runtime viaCoderRegistry.registerCoder(java.lang.Class<?>, java.lang.Class<?>)
. SeeCoderRegistry
for a more detailed discussion of the precedence rules.