Class CoderRegistry
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:
- Coder providers registered programmatically with
registerCoderProvider(CoderProvider)
. - A default coder provider for common Java (Byte, Double, List, ...) and Apache Beam (KV, ...) types.
- Coder providers registered automatically through a
CoderProviderRegistrar
using aServiceLoader
. Note that theServiceLoader
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.
-
Method Summary
Modifier and TypeMethodDescriptionstatic CoderRegistry
Creates a CoderRegistry containing registrations for all standard coders part of the core Java Apache Beam SDK and also any registrations provided bycoder registrars
.<T,
OutputT>
Coder<OutputT> getCoder
(Class<? extends T> subClass, Class<T> baseClass, Map<Type, ? extends Coder<?>> knownCoders, TypeVariable<?> param) Deprecated.This method is to change in an unknown backwards incompatible way once support for this functionality is refined.<T> Coder
<T> Returns theCoder
to use for values of the given class.<InputT,
OutputT>
Coder<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 theCoder
to use for values of the given type.<InputT,
OutputT>
Coder<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
(Class<?> clazz, Coder<?> coder) Registers the providedCoder
for the given class.void
registerCoderForType
(TypeDescriptor<?> type, Coder<?> coder) Registers the providedCoder
for the given type.void
registerCoderProvider
(CoderProvider coderProvider)
-
Method Details
-
createDefault
Creates a CoderRegistry containing registrations for all standard coders part of the core Java Apache Beam SDK and also any registrations provided bycoder 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 throughregisterCoderProvider(org.apache.beam.sdk.coders.CoderProvider)
.coder providers
for core types found within the Apache Beam Java SDK being used.- The
coder providers
from theCoderProviderRegistrar
with the lexicographically smallestclass name
being used.
-
registerCoderProvider
RegisterscoderProvider
as a potentialCoderProvider
which can produceCoder
instances.This method prioritizes this
CoderProvider
over all prior registered coders.See
CoderProviders
for commonCoderProvider
patterns. -
registerCoderForClass
Registers the providedCoder
for the given class.Note that this is equivalent to
registerCoderForType(TypeDescriptor.of(clazz))
. SeeregisterCoderForType(TypeDescriptor, Coder)
for further details. -
registerCoderForType
Registers the providedCoder
for the given type.Note that this is equivalent to
registerCoderProvider(CoderProviders.forCoder(type, coder))
. SeeregisterCoderProvider(org.apache.beam.sdk.coders.CoderProvider)
andCoderProviders.forCoder(org.apache.beam.sdk.values.TypeDescriptor<?>, org.apache.beam.sdk.coders.Coder<?>)
for further details. -
getCoder
Returns theCoder
to use for values of the given class.- Throws:
CannotProvideCoderException
- if aCoder
cannot be provided
-
getCoder
Returns theCoder
to use for values of the given type.- Throws:
CannotProvideCoderException
- if aCoder
cannot be provided
-
getCoder
@Deprecated @Internal public <InputT,OutputT> Coder<OutputT> getCoder(TypeDescriptor<OutputT> typeDescriptor, TypeDescriptor<InputT> inputTypeDescriptor, Coder<InputT> inputCoder) throws CannotProvideCoderException Deprecated.This method is to change in an unknown backwards incompatible way once support for this functionality is refined.- Throws:
CannotProvideCoderException
- if aCoder
cannot be provided
-
getOutputCoder
@Deprecated @Internal public <InputT,OutputT> Coder<OutputT> getOutputCoder(SerializableFunction<InputT, OutputT> fn, Coder<InputT> inputCoder) throws CannotProvideCoderExceptionDeprecated.This method is to change in an unknown backwards incompatible way once support for this functionality is refined.Returns theCoder
to use on elements produced by this function, given theCoder
used for its input elements.- Throws:
CannotProvideCoderException
- if aCoder
cannot be provided
-
getCoder
@Deprecated @Internal public <T,OutputT> Coder<OutputT> getCoder(Class<? extends T> subClass, Class<T> baseClass, Map<Type, ? extends Coder<?>> knownCoders, TypeVariable<?> param) throws CannotProvideCoderExceptionDeprecated.This method is to change in an unknown backwards incompatible way once support for this functionality is refined.Returns theCoder
to use for the specified type parameter specialization of the subclass, givenCoders
to use for all other type parameters (if any).- Throws:
CannotProvideCoderException
- if aCoder
cannot be provided
-