public class CoderRegistry
extends java.lang.Object
CoderRegistry
allows creating a Coder
for a given Java class
or
type descriptor
.
Creation of the Coder
is delegated to one of the many registered coder providers
based upon the registration order.
By default, the coder provider
precedence order is as follows:
registerCoderProvider(CoderProvider)
.
CoderProviderRegistrar
using a
ServiceLoader
. Note that the ServiceLoader
registration order is consistent
but may change due to the addition or removal of libraries exposed to the application. This
can impact the coder returned if multiple coder providers are capable of supplying a coder
for the specified type.
Note that if multiple coder providers
can provide a Coder
for a
given type, the precedence order above defines which CoderProvider
is chosen.
Modifier and Type | Method and Description |
---|---|
static CoderRegistry |
createDefault()
Creates a CoderRegistry containing registrations for all standard coders part of the core Java
Apache Beam SDK and also any registrations provided by
coder
registrars . |
<T,OutputT> |
getCoder(java.lang.Class<? extends T> subClass,
java.lang.Class<T> baseClass,
java.util.Map<java.lang.reflect.Type,? extends Coder<?>> knownCoders,
java.lang.reflect.TypeVariable<?> param)
Deprecated.
This method is to change in an unknown backwards incompatible way once support for
this functionality is refined.
|
<T> Coder<T> |
getCoder(java.lang.Class<T> clazz)
Returns the
Coder to use for values of the given class. |
<InputT,OutputT> |
getCoder(TypeDescriptor<OutputT> typeDescriptor,
TypeDescriptor<InputT> inputTypeDescriptor,
Coder<InputT> inputCoder)
Deprecated.
This method is to change in an unknown backwards incompatible way once support for
this functionality is refined.
|
<T> Coder<T> |
getCoder(TypeDescriptor<T> type)
Returns the
Coder to use for values of the given type. |
<InputT,OutputT> |
getOutputCoder(SerializableFunction<InputT,OutputT> fn,
Coder<InputT> inputCoder)
Deprecated.
This method is to change in an unknown backwards incompatible way once support for
this functionality is refined.
|
void |
registerCoderForClass(java.lang.Class<?> clazz,
Coder<?> coder)
Registers the provided
Coder for the given class. |
void |
registerCoderForType(TypeDescriptor<?> type,
Coder<?> coder)
Registers the provided
Coder for the given type. |
void |
registerCoderProvider(CoderProvider coderProvider)
|
public static CoderRegistry createDefault()
coder
registrars
.
Multiple registrations which can produce a coder for a given type result in a Coder created by the (in order of precedence):
coder providers
registered programmatically through registerCoderProvider(org.apache.beam.sdk.coders.CoderProvider)
.
coder providers
for core types found within the Apache Beam Java
SDK being used.
coder providers
from the CoderProviderRegistrar
with
the lexicographically smallest class name
being used.
public void registerCoderProvider(CoderProvider coderProvider)
coderProvider
as a potential CoderProvider
which can produce Coder
instances.
This method prioritizes this CoderProvider
over all prior registered coders.
See CoderProviders
for common CoderProvider
patterns.
public void registerCoderForClass(java.lang.Class<?> clazz, Coder<?> coder)
Coder
for the given class.
Note that this is equivalent to registerCoderForType(TypeDescriptor.of(clazz))
. See
registerCoderForType(TypeDescriptor, Coder)
for further details.
public void registerCoderForType(TypeDescriptor<?> type, Coder<?> coder)
Coder
for the given type.
Note that this is equivalent to registerCoderProvider(CoderProviders.forCoder(type,
coder))
. See registerCoderProvider(org.apache.beam.sdk.coders.CoderProvider)
and CoderProviders.forCoder(org.apache.beam.sdk.values.TypeDescriptor<?>, org.apache.beam.sdk.coders.Coder<?>)
for further
details.
public <T> Coder<T> getCoder(java.lang.Class<T> clazz) throws CannotProvideCoderException
Coder
to use for values of the given class.CannotProvideCoderException
- if a Coder
cannot be providedpublic <T> Coder<T> getCoder(TypeDescriptor<T> type) throws CannotProvideCoderException
Coder
to use for values of the given type.CannotProvideCoderException
- if a Coder
cannot be provided@Deprecated @Internal public <InputT,OutputT> Coder<OutputT> getCoder(TypeDescriptor<OutputT> typeDescriptor, TypeDescriptor<InputT> inputTypeDescriptor, Coder<InputT> inputCoder) throws CannotProvideCoderException
CannotProvideCoderException
- if a Coder
cannot be provided@Deprecated @Internal public <InputT,OutputT> Coder<OutputT> getOutputCoder(SerializableFunction<InputT,OutputT> fn, Coder<InputT> inputCoder) throws CannotProvideCoderException
Coder
to use on elements produced by this function, given the Coder
used for its input elements.CannotProvideCoderException
- if a Coder
cannot be provided@Deprecated @Internal public <T,OutputT> Coder<OutputT> getCoder(java.lang.Class<? extends T> subClass, java.lang.Class<T> baseClass, java.util.Map<java.lang.reflect.Type,? extends Coder<?>> knownCoders, java.lang.reflect.TypeVariable<?> param) throws CannotProvideCoderException
Coder
to use for the specified type parameter specialization of the
subclass, given Coders
to use for all other type parameters (if any).CannotProvideCoderException
- if a Coder
cannot be provided