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
CoderProviderRegistrarusing aServiceLoader. Note that theServiceLoaderregistration 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 CoderRegistryCreates 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 theCoderto 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 theCoderto 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.voidregisterCoderForClass(Class<?> clazz, Coder<?> coder) Registers the providedCoderfor the given class.voidregisterCoderForType(TypeDescriptor<?> type, Coder<?> coder) Registers the providedCoderfor the given type.voidregisterCoderProvider(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 providersregistered programmatically throughregisterCoderProvider(org.apache.beam.sdk.coders.CoderProvider).coder providersfor core types found within the Apache Beam Java SDK being used.- The
coder providersfrom theCoderProviderRegistrarwith the lexicographically smallestclass namebeing used.
-
registerCoderProvider
RegisterscoderProvideras a potentialCoderProviderwhich can produceCoderinstances.This method prioritizes this
CoderProviderover all prior registered coders.See
CoderProvidersfor commonCoderProviderpatterns. -
registerCoderForClass
Registers the providedCoderfor the given class.Note that this is equivalent to
registerCoderForType(TypeDescriptor.of(clazz)). SeeregisterCoderForType(TypeDescriptor, Coder)for further details. -
registerCoderForType
Registers the providedCoderfor 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 theCoderto use for values of the given class.- Throws:
CannotProvideCoderException- if aCodercannot be provided
-
getCoder
Returns theCoderto use for values of the given type.- Throws:
CannotProvideCoderException- if aCodercannot 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 aCodercannot 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 theCoderto use on elements produced by this function, given theCoderused for its input elements.- Throws:
CannotProvideCoderException- if aCodercannot 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 theCoderto use for the specified type parameter specialization of the subclass, givenCodersto use for all other type parameters (if any).- Throws:
CannotProvideCoderException- if aCodercannot be provided
-