@Documented @Retention(value=RUNTIME) @Target(value=TYPE) public @interface DefaultCoder
DefaultCoder annotation
specifies a default Coder class to handle encoding and decoding
instances of the annotated class.
The specified Coder must satisfy the requirements of
CoderProviders.fromStaticMethods(java.lang.Class<T>). Two classes provided by the SDK that
are intended for use with this annotation include SerializableCoder
and AvroCoder.
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(org.apache.beam.sdk.coders.Coder<T>)
take precedence, followed by Coders registered at runtime via
CoderRegistry.registerCoder(java.lang.Class<?>, java.lang.Class<?>). See CoderRegistry for a more detailed discussion
of the precedence rules.