public class CoderRegistry
extends java.lang.Object
CoderRegistry uses the following mechanisms to determine a
default Coder for a Java class, in order of precedence:
registerCoder(java.lang.Class<?>, java.lang.Class<?>). Built-in types are registered via
registerStandardCoders().
DefaultCoder can be used to annotate a type with
the default Coder type.
Serializable objects are given a default
Coder of SerializableCoder.
| Modifier and Type | Class and Description |
|---|---|
static class |
CoderRegistry.CoderFactory
A factory for default Coders for values of a particular class.
|
class |
CoderRegistry.ConstantCoderFactory
A factory that always returns the coder with which it is instantiated.
|
| Constructor and Description |
|---|
CoderRegistry() |
| Modifier and Type | Method and Description |
|---|---|
<T,O> Coder<O> |
getDefaultCoder(java.lang.Class<? extends T> subClass,
java.lang.Class<T> baseClass,
Coder<?>... knownCoders)
Returns the Coder to use for the last type parameter specialization
of the subclass given Coders to use for all other type parameters
specializations (if any).
|
<T,O> Coder<O> |
getDefaultCoder(java.lang.Class<? extends T> subClass,
java.lang.Class<T> baseClass,
java.util.Map<java.lang.String,? extends Coder<?>> knownCoders,
java.lang.String paramName)
Returns the Coder to use for the specified type parameter specialization
of the subclass, given Coders to use for all other type parameters
(if any).
|
<T> Coder<T> |
getDefaultCoder(T exampleValue)
Returns the Coder to use for the provided example value, if it can
be determined, otherwise returns
null. |
<I,O> Coder<O> |
getDefaultCoder(com.google.common.reflect.TypeToken<O> typeToken,
com.google.common.reflect.TypeToken<I> contextTypeToken,
Coder<I> contextCoder)
Returns the Coder to use by default for values of the given type,
where the given context type uses the given context coder,
or null if there is no default Coder.
|
<T> Coder<T> |
getDefaultCoder(com.google.common.reflect.TypeToken<T> typeToken)
Returns the Coder to use by default for values of the given type,
or null if there is no default Coder.
|
<T> Coder<?>[] |
getDefaultCoders(java.lang.Class<? extends T> subClass,
java.lang.Class<T> baseClass,
Coder<?>[] knownCoders)
Returns an array listing, for each of baseClass's type parameters, the
Coder to use by default for it, in the context of subClass's specialization
of baseClass.
|
<T> java.util.Map<java.lang.String,Coder<?>> |
getDefaultCoders(java.lang.Class<? extends T> subClass,
java.lang.Class<T> baseClass,
java.util.Map<java.lang.String,? extends Coder<?>> knownCoders)
Returns a Map from each of baseClass's type parameters to the Coder to
use by default for it, in the context of subClass's specialization of
baseClass.
|
<I,O> Coder<O> |
getDefaultOutputCoder(SerializableFunction<I,O> fn,
Coder<I> inputCoder)
Returns the Coder to use on elements produced by this function, given
the coder used for its input elements.
|
void |
registerCoder(java.lang.Class<?> clazz,
java.lang.Class<?> coderClazz)
Registers
coderClazz as the default Coder<T>
class to handle encoding and decoding instances of clazz
of type T. |
void |
registerCoder(java.lang.Class<?> rawClazz,
Coder<?> coder) |
void |
registerCoder(java.lang.Class<?> rawClazz,
CoderRegistry.CoderFactory coderFactory) |
void |
registerStandardCoders()
Registers standard Coders with this CoderRegistry.
|
public void registerStandardCoders()
public void registerCoder(java.lang.Class<?> clazz,
java.lang.Class<?> coderClazz)
coderClazz as the default Coder<T>
class to handle encoding and decoding instances of clazz
of type T.
coderClazz should have a static factory method with the
following signature:
public static Coder<T> of(Coder<X> argCoder1, Coder<Y> argCoder2, ...)
This method will be called to create instances of Coder<T>
for values of type T, passing Coders for each of the generic type
parameters of T. If T takes no generic type parameters,
then the of() factory method should have no arguments.
If T is a parameterized type, then it should additionally
have a method with the following signature:
public static List<Object> getInstanceComponents(T exampleValue);
This method will be called to decompose a value during the coder inference process, to automatically choose coders for the components
public void registerCoder(java.lang.Class<?> rawClazz,
CoderRegistry.CoderFactory coderFactory)
public void registerCoder(java.lang.Class<?> rawClazz,
Coder<?> coder)
public <T> Coder<T> getDefaultCoder(com.google.common.reflect.TypeToken<T> typeToken)
public <I,O> Coder<O> getDefaultCoder(com.google.common.reflect.TypeToken<O> typeToken, com.google.common.reflect.TypeToken<I> contextTypeToken, Coder<I> contextCoder)
public <I,O> Coder<O> getDefaultOutputCoder(SerializableFunction<I,O> fn, Coder<I> inputCoder)
public <T,O> Coder<O> getDefaultCoder(java.lang.Class<? extends T> subClass, java.lang.Class<T> baseClass, Coder<?>... knownCoders)
public <T,O> Coder<O> getDefaultCoder(java.lang.Class<? extends T> subClass, java.lang.Class<T> baseClass, java.util.Map<java.lang.String,? extends Coder<?>> knownCoders, java.lang.String paramName)
public <T> Coder<T> getDefaultCoder(T exampleValue)
null. If more than one
default coder matches, this will raise an exception.public <T> java.util.Map<java.lang.String,Coder<?>> getDefaultCoders(java.lang.Class<? extends T> subClass, java.lang.Class<T> baseClass, java.util.Map<java.lang.String,? extends Coder<?>> knownCoders)
For example, if baseClass is Map.class and subClass extends
Map<String, Integer> then this will return the registered Coders
to use for String and Integer as a {"K": stringCoder, "V": intCoder} Map.
The knownCoders parameter can be used to provide known coders for any of
the parameters which will be used to infer the others.
subClass - the concrete type whose specializations are being inferredbaseClass - the base type, a parameterized classknownCoders - a map corresponding to the set of known coders indexed
by parameter namepublic <T> Coder<?>[] getDefaultCoders(java.lang.Class<? extends T> subClass, java.lang.Class<T> baseClass, Coder<?>[] knownCoders)
For example, if baseClass is Map.class and subClass extends
Map<String, Integer> then this will return the registered Coders
to use for String and Integer in that order. The knownCoders parameter
can be used to provide known coders for any of the parameters which will
be used to infer the others.
If a type cannot be inferred, null is returned.
subClass - the concrete type whose specializations are being inferredbaseClass - the base type, a parameterized classknownCoders - an array corresponding to the set of base class
type parameters. Each entry is can be either a Coder (in which
case it will be used for inference) or null (in which case it
will be inferred). May be null to indicate the entire set of
parameters should be inferred.java.lang.IllegalArgumentException - if baseClass doesn't have type parameters
or if the length of knownCoders is not equal to the number of type
parameters